org.codehaus.jackson.map.ser
Class JsonValueSerializer
java.lang.Object
org.codehaus.jackson.map.JsonSerializer<T>
org.codehaus.jackson.map.ser.SerializerBase<Object>
org.codehaus.jackson.map.ser.JsonValueSerializer
- All Implemented Interfaces:
- ResolvableSerializer, SchemaAware
public final class JsonValueSerializer
- extends SerializerBase<Object>
- implements ResolvableSerializer, SchemaAware
Serializer class that can serialize Object that have a
JsonValue
annotation to
indicate that serialization should be done by calling the method
annotated, and serializing result it returns.
Implementation note: we will post-process resulting serializer
(much like what is done with BeanSerializer
)
to figure out actual serializers for final types. This must be
done from resolve(org.codehaus.jackson.map.SerializerProvider)
method, and NOT from constructor;
otherwise we could end up with an infinite loop.
_valueSerializer
protected JsonSerializer<Object> _valueSerializer
JsonValueSerializer
public JsonValueSerializer(Method valueMethod,
JsonSerializer<Object> ser)
- Parameters:
ser
- Explicit serializer to use, if caller knows it (which
occurs if and only if the "value method" was annotated with
JsonSerialize.using()
), otherwise
null
serialize
public void serialize(Object bean,
JsonGenerator jgen,
SerializerProvider prov)
throws IOException,
JsonGenerationException
- Description copied from class:
JsonSerializer
- Method that can be called to ask implementation to serialize
values of type this serializer handles.
- Specified by:
serialize
in class SerializerBase<Object>
- Parameters:
bean
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprov
- Provider that can be used to get serializers for
serializing Objects value contains, if any.
- Throws:
IOException
JsonGenerationException
getSchema
public JsonNode getSchema(SerializerProvider provider,
Type typeHint)
throws JsonMappingException
- Description copied from interface:
SchemaAware
- Get the representation of the schema to which this serializer will conform.
- Specified by:
getSchema
in interface SchemaAware
- Specified by:
getSchema
in class SerializerBase<Object>
- Parameters:
provider
- The serializer provider.typeHint
- A hint about the type.
- Returns:
- Json-schema for this serializer.
- Throws:
JsonMappingException
resolve
public void resolve(SerializerProvider provider)
throws JsonMappingException
- We can try to find the actual serializer for value, if we can
statically figure out what the result type must be.
- Specified by:
resolve
in interface ResolvableSerializer
- Parameters:
provider
- Provider that has constructed serializer this method
is called on.
- Throws:
JsonMappingException
toString
public String toString()
- Overrides:
toString
in class Object