com.fasterxml.jackson.annotation.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 method, and NOT from constructor;
otherwise we could end up with an infinite loop.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | JsonValueSerializer.
Silly little wrapper class we need to re-route type serialization so that we can override Object to use for type id (logical type) even when asking serialization of something else (delegate type) |
| Modifier and Type | Field and Description |
|---|---|
| protected final AnnotatedMember | _accessor
Accessor (field, getter) used to access value to serialize. |
| protected final 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 final Set | |
| protected final boolean | |
| protected final JavaType | _valueType
Value for annotated accessor. |
| Access | Constructor and Description |
|---|---|
| protected | JsonValueSerializer(JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?>
Explicit serializer to use, if caller knows it (which
occurs if and only if the "value method" was annotated with
ser, AnnotatedMember accessor, Set<String> ignoredProperties)tools.), otherwise
null
|
| protected | JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)
|
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: True if method handled callbacks; false if not; in latter case caller will send default callbacksOverridable helper method used for special case handling of schema information for Enums. |
| protected ValueSerializer | |
| protected static ValueSerializer | Returns: Configured serializer with specified properties ignoredSerializer to be configured ser, Set<String> Properties to ignore, if any ignoredProperties)Internal helper that configures the provided |
| public void | acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
Overrides tools. Implements tools. Default implementation specifies no format. |
| public static JsonValueSerializer | construct(SerializationConfig config, JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor)
|
| public ValueSerializer | createContextual(SerializationContext ctxt, BeanProperty property)
Overrides tools. We can try to find the actual serializer for value, if we can statically figure out what the result type must be. |
| public boolean | isEmpty(SerializationContext ctxt, Object bean)
Overrides tools. Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values). |
| protected boolean | |
| public void | serialize(final Object bean, final JsonGenerator gen, final SerializationContext ctxt)
Implements abstract tools. Method that can be called to ask implementation to serialize values of type this serializer handles. |
| public void | serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer0)
Overrides tools. 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. |
| public JsonValueSerializer | withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)
|
| _accessor | back to summary |
|---|---|
| protected final AnnotatedMember _accessor Accessor (field, getter) used to access value to serialize. | |
| _forceTypeInformation | back to summary |
|---|---|
| protected final 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. | |
| _ignoredProperties | back to summary |
|---|---|
| protected final Set<String> _ignoredProperties | |
| _staticTyping | back to summary |
|---|---|
| protected final boolean _staticTyping | |
| _valueType | back to summary |
|---|---|
| protected final JavaType _valueType Value for annotated accessor. | |
| JsonValueSerializer | back to summary |
|---|---|
protected JsonValueSerializer(JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor, Set<String> ignoredProperties)
| |
| JsonValueSerializer | back to summary |
|---|---|
| protected JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo) | |
| _acceptJsonFormatVisitorForEnum | back to summary |
|---|---|
| protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType) Overridable helper method used for special case handling of schema information for Enums.
| |
| _findSerializer | back to summary |
|---|---|
| protected ValueSerializer | |
| _withIgnoreProperties | back to summary |
|---|---|
| protected static ValueSerializer Internal helper that configures the provided
| |
| acceptJsonFormatVisitor | back to summary |
|---|---|
| public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) Overrides tools. Implements tools. Doc from tools. Default implementation specifies no format. This behavior is usually overriden by custom serializers.
| |
| construct | back to summary |
|---|---|
| public static JsonValueSerializer construct(SerializationConfig config, JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor) | |
| createContextual | back to summary |
|---|---|
| public ValueSerializer Overrides tools. We can try to find the actual serializer for value, if we can statically figure out what the result type must be.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty(SerializationContext ctxt, Object bean) Overrides tools. Doc from tools. Method 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.
| |
| isNaturalTypeWithStdHandling | back to summary |
|---|---|
| protected boolean isNaturalTypeWithStdHandling(Class<?> rawType, ValueSerializer<?> ser) | |
| serialize | back to summary |
|---|---|
| public void serialize(final Object bean, final JsonGenerator gen, final SerializationContext ctxt) throws JacksonException Implements abstract tools. Doc from tools. Method that can be called to ask implementation to serialize values of type this serializer handles.
| |
| serializeWithType | back to summary |
|---|---|
| public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer0) throws JacksonException Overrides tools. Doc from tools. 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 throw 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, as START-ARRAY/END-ARRAY and
START-OBJECT/END-OBJECT pairs
need to be properly handled with respect to serializing of contents.
| |
| withResolved | back to summary |
|---|---|
| public JsonValueSerializer withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo) | |
| Modifier and Type | Field and Description |
|---|---|
| protected final Object | |
| protected final TypeSerializer |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public TypeSerializer | forProperty(SerializationContext ctxt, BeanProperty prop)
Implements abstract tools. Method called to create contextual version, to be used for values of given property. |
| public String | getPropertyName()
Implements abstract tools. Name of property that contains type information, if property-based inclusion is used. |
| public TypeIdResolver | getTypeIdResolver()
Implements abstract tools. Accessor for object that handles conversions between types and matching type ids. |
| public JsonTypeInfo. | getTypeInclusion()
Implements abstract tools. Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON. |
| public WritableTypeId | writeTypePrefix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId)
Implements abstract tools. Method called to write initial part of type information for given value, along with possible wrapping to use: details are specified by `typeId` argument. |
| public WritableTypeId | writeTypeSuffix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId)
Implements abstract tools. Method called to write the "closing" part of type information for given
value, along with possible closing wrapping to use: details are specified
by `typeId` argument, which should be one returned from an earlier matching
call to |
| _forObject | back to summary |
|---|---|
| protected final Object _forObject | |
| _typeSerializer | back to summary |
|---|---|
| protected final TypeSerializer _typeSerializer | |
| TypeSerializerRerouter | back to summary |
|---|---|
| public TypeSerializerRerouter(TypeSerializer ts, Object ob) | |
| forProperty | back to summary |
|---|---|
| public TypeSerializer forProperty(SerializationContext ctxt, BeanProperty prop) Implements abstract tools. Doc from tools. Method called to create contextual version, to be used for
values of given property. This may be the type itself
(as is the case for bean properties), or values contained
(for Note since 3.0 has received context object as first argument.
| |
| getPropertyName | back to summary |
|---|---|
| public String getPropertyName() Implements abstract tools. Doc from tools. Name of property that contains type information, if property-based inclusion is used.
| |
| getTypeIdResolver | back to summary |
|---|---|
| public TypeIdResolver getTypeIdResolver() Implements abstract tools. Doc from tools. Accessor for object that handles conversions between types and matching type ids.
| |
| getTypeInclusion | back to summary |
|---|---|
| public JsonTypeInfo. Implements abstract tools. Doc from tools. Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.
| |
| writeTypePrefix | back to summary |
|---|---|
| public WritableTypeId writeTypePrefix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId) throws JacksonException Implements abstract tools. Doc from tools. Method called to write initial part of type information for given value, along with possible wrapping to use: details are specified by `typeId` argument. Note that for structured types (Object, Array), this call will add necessary start token so it should NOT be explicitly written, unlike with non-type-id value writes.
| |
| writeTypeSuffix | back to summary |
|---|---|
| public WritableTypeId writeTypeSuffix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId) throws JacksonException Implements abstract tools. Doc from tools. Method called to write the "closing" part of type information for given
value, along with possible closing wrapping to use: details are specified
by `typeId` argument, which should be one returned from an earlier matching
call to
| |