package com.cedarsoft.serialization.jackson; import com.cedarsoft.version.Version; import com.cedarsoft.version.VersionException; import com.cedarsoft.version.VersionRange; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import javax.annotation.Nonnull; import javax.inject.Inject; import java.io.IOException; /** * @author Johannes Schneider (<a href="mailto:js@cedarsoft.com">js@cedarsoft.com</a>) */ public class IntegerSerializer extends AbstractJacksonSerializer<Integer> { @Inject public IntegerSerializer() { super( "int", VersionRange.single( 1, 0, 0 ) ); } @Override public void serialize( @Nonnull JsonGenerator serializeTo, @Nonnull Integer object, @Nonnull Version formatVersion ) throws IOException, VersionException, JsonProcessingException { serializeTo.writeNumber( object ); } @Nonnull @Override public Integer deserialize( @Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion ) throws IOException, VersionException, JsonProcessingException { return deserializeFrom.getIntValue(); } @Override public boolean isObjectType() { return false; } }