com.cedarsoft.serialization.stax.mate.primitives.NumberSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stax-mate Show documentation
Show all versions of stax-mate Show documentation
Path: :open:serialization:stax-mate
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 NumberSerializer extends AbstractStaxMateSerializer {
public NumberSerializer() {
super( "number", "http://cedarsoft.com/primitives", VersionRange.single( 1, 0, 0 ) );
}
@Override
public void serialize( @Nonnull SMOutputElement serializeTo, @Nonnull Number object, @Nonnull Version formatVersion ) throws IOException, VersionException, XMLStreamException {
serializeTo.addCharacters( String.valueOf( object ) );
}
@Nonnull
@Override
public Number deserialize( @Nonnull XMLStreamReader deserializeFrom, @Nonnull Version formatVersion ) throws IOException, VersionException, XMLStreamException {
return Double.parseDouble( getText( deserializeFrom ) );
}
}