All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cedarsoft.serialization.stax.mate.primitives.FloatSerializer Maven / Gradle / Ivy

There is a newer version: 8.9.2
Show newest version
package com.cedarsoft.serialization.stax.mate.primitives;

import com.cedarsoft.serialization.stax.mate.AbstractStaxMateSerializer;
import com.cedarsoft.version.Version;
import com.cedarsoft.version.VersionException;
import com.cedarsoft.version.VersionRange;
import org.codehaus.staxmate.out.SMOutputElement;

import javax.annotation.Nonnull;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;

/**
 * @author Johannes Schneider ([email protected])
 */
public class FloatSerializer extends AbstractStaxMateSerializer {
  public FloatSerializer() {
    super( "float", "http://cedarsoft.com/primitives", VersionRange.single( 1, 0, 0 ) );
  }

  @Override
  public void serialize( @Nonnull SMOutputElement serializeTo, @Nonnull Float object, @Nonnull Version formatVersion ) throws IOException, VersionException, XMLStreamException {
    serializeTo.addCharacters( String.valueOf( object ) );
  }

  @Nonnull
  @Override
  public Float deserialize( @Nonnull XMLStreamReader deserializeFrom, @Nonnull Version formatVersion ) throws IOException, VersionException, XMLStreamException {
    return Float.parseFloat( getText( deserializeFrom ) );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy