public class JsonValueSerializer extends SerializerBase<Object> implements ResolvableSerializer, SchemaAware
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.JsonSerializer.None
Modifier and Type | Field and Description |
---|---|
protected Method |
_accessorMethod |
protected boolean |
_forceTypeInformation
This is a flag that is set in rare (?) cases where this serializer
is used for "natural" types (boolean, int, String, double); and where
we actually must force type information wrapping, even though
one would not normally be added.
|
protected BeanProperty |
_property |
protected JsonSerializer<Object> |
_valueSerializer |
_handledType
Constructor and Description |
---|
JsonValueSerializer(Method valueMethod,
JsonSerializer<Object> ser,
BeanProperty property) |
Modifier and Type | Method and Description |
---|---|
JsonNode |
getSchema(SerializerProvider provider,
Type typeHint)
Note: since Jackson 1.9, default implementation claims type is "string"
|
protected boolean |
isNaturalTypeWithStdHandling(JavaType type,
JsonSerializer<?> ser) |
void |
resolve(SerializerProvider provider)
We can try to find the actual serializer for value, if we can
statically figure out what the result type must be.
|
void |
serialize(Object bean,
JsonGenerator jgen,
SerializerProvider prov)
Method that can be called to ask implementation to serialize
values of type this serializer handles.
|
void |
serializeWithType(Object bean,
JsonGenerator jgen,
SerializerProvider provider,
TypeSerializer typeSer)
Method that can be called to ask implementation to serialize
values of type this serializer handles, using specified type serializer
for embedding necessary type information.
|
String |
toString() |
createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrow
isUnwrappingSerializer, unwrappingSerializer
protected final Method _accessorMethod
protected JsonSerializer<Object> _valueSerializer
protected final BeanProperty _property
protected boolean _forceTypeInformation
public JsonValueSerializer(Method valueMethod, JsonSerializer<Object> ser, BeanProperty property)
ser
- Explicit serializer to use, if caller knows it (which
occurs if and only if the "value method" was annotated with
JsonSerialize.using()
), otherwise
nullpublic void serialize(Object bean, JsonGenerator jgen, SerializerProvider prov) throws IOException, JsonGenerationException
JsonSerializer
serialize
in class SerializerBase<Object>
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.IOException
JsonGenerationException
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException
JsonSerializer
Default implementation will ignore serialization of type information,
and just calls JsonSerializer.serialize(T, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.map.SerializerProvider)
: serializers that can embed
type information should override this to implement actual handling.
Most common such handling is done by something like:
// 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);
serializeWithType
in class JsonSerializer<Object>
bean
- Value to serialize; can not be null.jgen
- Generator used to output resulting Json contentprovider
- Provider that can be used to get serializers for
serializing Objects value contains, if any.typeSer
- Type serializer to use for including type informationIOException
JsonProcessingException
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException
SerializerBase
getSchema
in interface SchemaAware
getSchema
in class SerializerBase<Object>
provider
- The serializer provider.typeHint
- A hint about the type.JsonMappingException
public void resolve(SerializerProvider provider) throws JsonMappingException
resolve
in interface ResolvableSerializer
provider
- Provider that has constructed serializer this method
is called on.JsonMappingException
protected boolean isNaturalTypeWithStdHandling(JavaType type, JsonSerializer<?> ser)