package sh.calaba.org.codehaus.jackson.map; import java.io.IOException; import sh.calaba.org.codehaus.jackson.JsonGenerator; import sh.calaba.org.codehaus.jackson.JsonProcessingException; /** * Abstract class that defines API used by {@link ObjectMapper} (and * other chained {@link JsonSerializer}s too) to serialize Objects of * arbitrary types into JSON, using provided {@link JsonGenerator}. *
* NOTE: it is recommended that custom serializers extend
* {@link sh.calaba.org.codehaus.jackson.map.ser.std.SerializerBase} instead
* of this class, since it will implement many of optional
* methods of this class.
*/
public abstract class JsonSerializer
* Default implementation just returns serializer as-is,
* indicating that no unwrapped variant exists
*
* @since 1.9
*/
public JsonSerializer
* Default implementation will ignore serialization of type information,
* and just calls {@link #serialize}: serializers that can embed
* type information should override this to implement actual handling.
* Most common such handling is done by something like:
*
* Default implementation will return null, which essentially means
* same as returning
*/
public Class
* Specifically, this class is to be used as the marker for
* annotation {@link sh.calaba.org.codehaus.jackson.map.annotate.JsonSerialize}.
*/
public abstract static class None
extends JsonSerializer
* // note: method to call depends on whether this type is serialized as JSON scalar, object or Array!
* typeSer.writeTypePrefixForScalar(value, jgen);
* serialize(value, jgen, provider);
* typeSer.writeTypeSuffixForScalar(value, jgen);
*
*
* @param value Value to serialize; can not be null.
* @param jgen Generator used to output resulting Json content
* @param provider Provider that can be used to get serializers for
* serializing Objects value contains, if any.
* @param typeSer Type serializer to use for including type information
*
* @since 1.5
*/
public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
serialize(value, jgen, provider);
}
/*
/**********************************************************
/* Introspection methods needed for type handling
/**********************************************************
*/
/**
* Method for accessing type of Objects this serializer can handle.
* Note that this information is not guaranteed to be exact -- it
* may be a more generic (super-type) -- but it should not be
* incorrect (return a non-related type).
*Object.class
would; that is, that
* nothing is known about handled type.
*