Package org.codehaus.jackson.map.ser.std
Class JsonValueSerializer
- java.lang.Object
-
- org.codehaus.jackson.map.JsonSerializer<T>
-
- org.codehaus.jackson.map.ser.std.SerializerBase<java.lang.Object>
-
- org.codehaus.jackson.map.ser.std.JsonValueSerializer
-
- All Implemented Interfaces:
ResolvableSerializer,SchemaAware
public class JsonValueSerializer extends SerializerBase<java.lang.Object> implements ResolvableSerializer, SchemaAware
Serializer class that can serialize Object that have aJsonValueannotation 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 withBeanSerializer) to figure out actual serializers for final types. This must be done fromresolve(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
Fields Modifier and Type Field Description protected java.lang.reflect.Method_accessorMethodprotected 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.protected BeanProperty_propertyprotected JsonSerializer<java.lang.Object>_valueSerializer-
Fields inherited from class org.codehaus.jackson.map.ser.std.SerializerBase
_handledType
-
-
Constructor Summary
Constructors Constructor Description JsonValueSerializer(java.lang.reflect.Method valueMethod, JsonSerializer<java.lang.Object> ser, BeanProperty property)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonNodegetSchema(SerializerProvider provider, java.lang.reflect.Type typeHint)Note: since Jackson 1.9, default implementation claims type is "string"protected booleanisNaturalTypeWithStdHandling(JavaType type, JsonSerializer<?> ser)voidresolve(SerializerProvider provider)We can try to find the actual serializer for value, if we can statically figure out what the result type must be.voidserialize(java.lang.Object bean, JsonGenerator jgen, SerializerProvider prov)Method that can be called to ask implementation to serialize values of type this serializer handles.voidserializeWithType(java.lang.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.java.lang.StringtoString()-
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 Detail
-
_accessorMethod
protected final java.lang.reflect.Method _accessorMethod
-
_valueSerializer
protected JsonSerializer<java.lang.Object> _valueSerializer
-
_property
protected final BeanProperty _property
-
_forceTypeInformation
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.- Since:
- 1.7
-
-
Constructor Detail
-
JsonValueSerializer
public JsonValueSerializer(java.lang.reflect.Method valueMethod, JsonSerializer<java.lang.Object> ser, BeanProperty property)- 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 Detail
-
serialize
public void serialize(java.lang.Object bean, JsonGenerator jgen, SerializerProvider prov) throws java.io.IOException, JsonGenerationExceptionDescription copied from class:JsonSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classSerializerBase<java.lang.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:
java.io.IOExceptionJsonGenerationException
-
serializeWithType
public void serializeWithType(java.lang.Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws java.io.IOException, JsonProcessingExceptionDescription copied from class:JsonSerializerMethod 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:
serializeWithTypein classJsonSerializer<java.lang.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:
java.io.IOExceptionJsonProcessingException
-
getSchema
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) throws JsonMappingException
Description copied from class:SerializerBaseNote: since Jackson 1.9, default implementation claims type is "string"- Specified by:
getSchemain interfaceSchemaAware- Overrides:
getSchemain classSerializerBase<java.lang.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:
resolvein interfaceResolvableSerializer- Parameters:
provider- Provider that has constructed serializer this method is called on.- Throws:
JsonMappingException
-
isNaturalTypeWithStdHandling
protected boolean isNaturalTypeWithStdHandling(JavaType type, JsonSerializer<?> ser)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-