se.l4.commons.serialization.standard.CharacterSerializer Maven / Gradle / Ivy
package se.l4.commons.serialization.standard;
import java.io.IOException;
import se.l4.commons.serialization.Serializer;
import se.l4.commons.serialization.SerializerFormatDefinition;
import se.l4.commons.serialization.format.StreamingInput;
import se.l4.commons.serialization.format.StreamingOutput;
import se.l4.commons.serialization.format.Token;
import se.l4.commons.serialization.format.ValueType;
/**
* Serializer for {@link Character}.
*
* @author Andreas Holstenson
*
*/
public class CharacterSerializer
implements Serializer
{
private final SerializerFormatDefinition formatDefinition;
public CharacterSerializer()
{
formatDefinition = SerializerFormatDefinition.forValue(ValueType.CHAR);
}
@Override
public Character read(StreamingInput in)
throws IOException
{
in.next(Token.VALUE);
return in.getChar();
}
@Override
public void write(Character object, String name, StreamingOutput stream)
throws IOException
{
stream.write(name, object);
}
@Override
public SerializerFormatDefinition getFormatDefinition()
{
return formatDefinition;
}
}