/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(value, JsonToken.VALUE_STRING)); serialize(value, g, provider); typeSer.writeTypeSuffix(g, typeIdDef); }
public class TryJsonStringSerializer extends JsonSerializer<String> { private RawSerializer<String> rawSerializer = new RawSerializer<String>(String.class); private ToStringSerializer stringSerializer = ToStringSerializer.instance; @Override public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { if (value == null) { return; } value = value.trim(); if (value.startsWith("{") && value.endsWith("}")) { rawSerializer.serialize(value, jsonGenerator, serializerProvider); } else { stringSerializer.serialize(value, jsonGenerator, serializerProvider); } } }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException { typeSer.writeTypePrefixForScalar(value, jgen); serialize(value, jgen, provider); typeSer.writeTypeSuffixForScalar(value, jgen); }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException { typeSer.writeTypePrefixForScalar(value, jgen); serialize(value, jgen, provider); typeSer.writeTypeSuffixForScalar(value, jgen); }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(value, JsonToken.VALUE_STRING)); serialize(value, g, provider); typeSer.writeTypeSuffix(g, typeIdDef); }