Package org.codehaus.jackson.map.ser.std
Class JsonValueSerializer
java.lang.Object
org.codehaus.jackson.map.JsonSerializer<Object>
org.codehaus.jackson.map.ser.std.SerializerBase<Object>
org.codehaus.jackson.map.ser.std.JsonValueSerializer
- All Implemented Interfaces:
ResolvableSerializer
,SchemaAware
public 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.-
Nested Class Summary
Nested classes/interfaces inherited from class org.codehaus.jackson.map.JsonSerializer
JsonSerializer.None
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Method
protected boolean
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 final BeanProperty
protected JsonSerializer
<Object> Fields inherited from class org.codehaus.jackson.map.ser.std.SerializerBase
_handledType
-
Constructor Summary
ConstructorsConstructorDescriptionJsonValueSerializer
(Method valueMethod, JsonSerializer<Object> ser, BeanProperty property) -
Method Summary
Modifier and TypeMethodDescriptiongetSchema
(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.toString()
Methods inherited from class org.codehaus.jackson.map.ser.std.SerializerBase
createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrow
Methods inherited from class org.codehaus.jackson.map.JsonSerializer
isUnwrappingSerializer, unwrappingSerializer
-
Field Details
-
_accessorMethod
-
_valueSerializer
-
_property
-
_forceTypeInformation
protected boolean _forceTypeInformationThis 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.- Since:
- 1.7
-
-
Constructor Details
-
JsonValueSerializer
- Parameters:
ser
- Explicit serializer to use, if caller knows it (which occurs if and only if the "value method" was annotated withJsonSerialize.using()
), otherwise null
-
-
Method Details
-
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 classSerializerBase<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
-
serializeWithType
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException Description copied from class:JsonSerializer
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.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);
- Overrides:
serializeWithType
in classJsonSerializer<Object>
- Parameters:
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 information- Throws:
IOException
JsonProcessingException
-
getSchema
Description copied from class:SerializerBase
Note: since Jackson 1.9, default implementation claims type is "string"- Specified by:
getSchema
in interfaceSchemaAware
- Overrides:
getSchema
in classSerializerBase<Object>
- Parameters:
provider
- The serializer provider.typeHint
- A hint about the type.- Returns:
- Json-schema for this serializer.
- Throws:
JsonMappingException
-
resolve
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 interfaceResolvableSerializer
- Parameters:
provider
- Provider that has constructed serializer this method is called on.- Throws:
JsonMappingException
-
isNaturalTypeWithStdHandling
-
toString
-