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(SerializerProvider) method, and NOT from constructor;
otherwise we could end up with an infinite loop.-
Nested Class Summary
Nested classes/interfaces inherited from class JsonSerializer
JsonSerializer.None -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Methodprotected booleanThis 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 BeanPropertyprotected JsonSerializer<Object> Fields inherited from class 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 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(Object bean, JsonGenerator jgen, SerializerProvider prov) Method that can be called to ask implementation to serialize values of type this serializer handles.voidserializeWithType(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 SerializerBase
createObjectNode, createSchemaNode, createSchemaNode, handledType, isDefaultSerializer, wrapAndThrow, wrapAndThrow, wrapAndThrow, wrapAndThrowMethods inherited from class 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:JsonSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein 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:
IOExceptionJsonGenerationException
-
serializeWithType
public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonProcessingException Description 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, JsonGenerator, 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<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:
IOExceptionJsonProcessingException
-
getSchema
Description copied from class:SerializerBaseNote: since Jackson 1.9, default implementation claims type is "string"- Specified by:
getSchemain interfaceSchemaAware- Overrides:
getSchemain 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:
resolvein interfaceResolvableSerializer- Parameters:
provider- Provider that has constructed serializer this method is called on.- Throws:
JsonMappingException
-
isNaturalTypeWithStdHandling
-
toString
-