java.lang.Object
tools.jackson.databind.ValueSerializer<T>
tools.jackson.databind.ser.std.StdSerializer<T>
tools.jackson.databind.ser.std.StdDynamicSerializer<Object>
tools.jackson.databind.ser.jackson.JsonValueSerializer
- All Implemented Interfaces:
JsonFormatVisitable
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 createContextual(tools.jackson.databind.SerializationContext, tools.jackson.databind.BeanProperty) method, and NOT from constructor;
otherwise we could end up with an infinite loop.
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jackson.databind.ValueSerializer
ValueSerializer.None -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AnnotatedMemberAccessor (field, getter) used to access value to serialize.protected final booleanThis is a flag that is set in rare (?)protected final booleanprotected final JavaTypeValue for annotated accessor.Fields inherited from class tools.jackson.databind.ser.std.StdDynamicSerializer
_dynamicValueSerializers, _property, _valueSerializer, _valueTypeSerializerFields inherited from class tools.jackson.databind.ser.std.StdSerializer
_handledType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJsonValueSerializer(JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor, Set<String> ignoredProperties) protectedJsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean_acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType) Overridable helper method used for special case handling of schema information for Enums.protected ValueSerializer<Object>_findSerializer(SerializationContext ctxt, Object value) protected static ValueSerializer<Object>_withIgnoreProperties(ValueSerializer<?> ser, Set<String> ignoredProperties) Internal helper that configures the providedserto ignore properties specified byJsonIgnoreProperties.voidacceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) Default implementation specifies no format.static JsonValueSerializerconstruct(SerializationConfig config, JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor) createContextual(SerializationContext ctxt, BeanProperty property) We can try to find the actual serializer for value, if we can statically figure out what the result type must be.booleanisEmpty(SerializationContext ctxt, Object bean) Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).protected booleanisNaturalTypeWithStdHandling(Class<?> rawType, ValueSerializer<?> ser) voidserialize(Object bean, JsonGenerator gen, SerializationContext ctxt) Method that can be called to ask implementation to serialize values of type this serializer handles.voidserializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer0) 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.withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo) Methods inherited from class tools.jackson.databind.ser.std.StdDynamicSerializer
_findAndAddDynamic, _findAndAddDynamic, _findAndAddDynamic, _findAndAddDynamicMethods inherited from class tools.jackson.databind.ser.std.StdSerializer
_neitherNull, _nonEmpty, _wrapIOFailure, acceptJsonFormatVisitorForBinary, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrowMethods inherited from class tools.jackson.databind.ValueSerializer
getDelegatee, isUnwrappingSerializer, properties, replaceDelegatee, resolve, unwrappingSerializer, usesObjectId, withFilterId, withFormatOverrides, withIgnoredProperties
-
Field Details
-
_accessor
Accessor (field, getter) used to access value to serialize. -
_valueType
Value for annotated accessor. -
_staticTyping
protected final boolean _staticTyping -
_forceTypeInformation
protected final 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. -
_ignoredProperties
-
-
Constructor Details
-
JsonValueSerializer
protected JsonValueSerializer(JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor, Set<String> ignoredProperties) - 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
-
JsonValueSerializer
protected JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)
-
-
Method Details
-
construct
public static JsonValueSerializer construct(SerializationConfig config, JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor) -
withResolved
public JsonValueSerializer withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo) -
isEmpty
Description copied from class:ValueSerializerMethod called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).Default implementation will consider only null values to be empty.
- Overrides:
isEmptyin classValueSerializer<Object>
-
createContextual
We can try to find the actual serializer for value, if we can statically figure out what the result type must be.- Overrides:
createContextualin classValueSerializer<Object>- Parameters:
ctxt- Context to use for accessing config, other serializersproperty- Property (defined by one or more accessors - field or method - used for accessing logical property value) for which serializer is used to be used; or, `null` for root value (or in cases where caller does not have this information, which is handled as root value case).- Returns:
- Serializer to use for serializing values of specified property; may be this instance or a new instance.
-
serialize
public void serialize(Object bean, JsonGenerator gen, SerializationContext ctxt) throws JacksonException Description copied from class:ValueSerializerMethod that can be called to ask implementation to serialize values of type this serializer handles.- Specified by:
serializein classStdSerializer<Object>- Parameters:
bean- Value to serialize; can not be null.gen- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.- Throws:
JacksonException
-
_findSerializer
-
_withIgnoreProperties
protected static ValueSerializer<Object> _withIgnoreProperties(ValueSerializer<?> ser, Set<String> ignoredProperties) Internal helper that configures the providedserto ignore properties specified byJsonIgnoreProperties.- Parameters:
ser- Serializer to be configuredignoredProperties- Properties to ignore, if any- Returns:
- Configured serializer with specified properties ignored
-
serializeWithType
public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer0) throws JacksonException Description copied from class:ValueSerializerMethod 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 throw
UnsupportedOperationExceptionto indicate that proper type handling needs to be implemented.For simple datatypes written as a single scalar value (JSON String, Number, Boolean), implementation would look like:
// note: method to call depends on whether this type is serialized as JSON scalar, object or Array! typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen);
and implementations for type serialized as JSON Arrays or Objects would differ slightly, asSTART-ARRAY/END-ARRAYandSTART-OBJECT/END-OBJECTpairs need to be properly handled with respect to serializing of contents.- Overrides:
serializeWithTypein classValueSerializer<Object>- Parameters:
bean- Value to serialize; can not be null.gen- Generator used to output resulting Json contentctxt- Context that can be used to get serializers for serializing Objects value contains, if any.typeSer0- Type serializer to use for including type information- Throws:
JacksonException
-
acceptJsonFormatVisitor
Description copied from class:StdSerializerDefault implementation specifies no format. This behavior is usually overriden by custom serializers.- Specified by:
acceptJsonFormatVisitorin interfaceJsonFormatVisitable- Overrides:
acceptJsonFormatVisitorin classStdSerializer<Object>typeHint- Type of element (entity like property) being visited
-
_acceptJsonFormatVisitorForEnum
protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType) Overridable helper method used for special case handling of schema information for Enums.- Returns:
- True if method handled callbacks; false if not; in latter case caller will send default callbacks
-
isNaturalTypeWithStdHandling
-