import org.jetbrains.annotations.NotNull; import java.io.IOException; public class SetterSerializer extends com.cedarsoft.serialization.jackson.AbstractJacksonSerializer<Setter> { public static final String PROPERTY_FOO = "foo"; @javax.inject.Inject public SetterSerializer(@NotNull StringSerializer stringSerializer) { super("setter", com.cedarsoft.version.VersionRange.from(1, 0, 0).to()); getDelegatesMappings().add(stringSerializer).responsibleFor(String.class).map(1, 0, 0).toDelegateVersion(1, 0, 0); assert getDelegatesMappings().verify(); } @Override public void serialize(@NotNull com.fasterxml.jackson.core.JsonGenerator serializeTo, @NotNull Setter object, @NotNull com.cedarsoft.version.Version formatVersion) throws IOException, com.cedarsoft.version.VersionException, com.fasterxml.jackson.core.JsonProcessingException { verifyVersionWritable(formatVersion); serialize(object.getFoo(), String.class, PROPERTY_FOO, serializeTo, formatVersion); } @Override @NotNull public Setter deserialize(@NotNull com.fasterxml.jackson.core.JsonParser deserializeFrom, @NotNull com.cedarsoft.version.Version formatVersion) throws IOException, com.cedarsoft.version.VersionException, com.fasterxml.jackson.core.JsonProcessingException { verifyVersionWritable(formatVersion); String foo = null; com.cedarsoft.serialization.jackson.JacksonParserWrapper parser = new com.cedarsoft.serialization.jackson.JacksonParserWrapper(deserializeFrom); while (parser.nextToken() == com.fasterxml.jackson.core.JsonToken.FIELD_NAME) { String currentName = parser.getCurrentName(); if (currentName.equals(PROPERTY_FOO)) { parser.nextToken(); foo = deserialize(String.class, formatVersion, deserializeFrom); continue; } throw new IllegalStateException("Unexpected field reached <" + currentName + ">"); } parser.verifyDeserialized(foo, PROPERTY_FOO); assert foo != null; parser.ensureObjectClosed(); Setter object = new Setter(); object.setFoo(foo); return object; } }