Top Description Inners Fields Constructors Methods
tools.jackson.databind.ser.jackson

public Class JsonValueSerializer

extends StdDynamicSerializer<Object>
Class Inheritance
Annotations
@JacksonStdImpl
Imports
java.lang.reflect.InvocationTargetException, java.util.LinkedHashSet, .Set, java.util.function.UnaryOperator, com.fasterxml.jackson.annotation.JsonIgnoreProperties, .JsonTypeInfo.As, tools.jackson.core.*, tools.jackson.core.type.WritableTypeId, tools.jackson.databind.*, tools.jackson.databind.annotation.JacksonStdImpl, tools.jackson.databind.introspect.AnnotatedMember, tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, .JsonStringFormatVisitor, tools.jackson.databind.jsontype.TypeIdResolver, .TypeSerializer, tools.jackson.databind.ser.BeanSerializer, tools.jackson.databind.ser.std.StdDynamicSerializer, tools.jackson.databind.util.ClassUtil

Serializer class that can serialize Object that have a 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
JsonValueSerializer.TypeSerializerRerouter

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)

Field Summary

Modifier and TypeField 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<String>
protected final boolean
protected final JavaType
_valueType

Value for annotated accessor.

Inherited from tools.jackson.databind.ser.std.StdDynamicSerializer:
_dynamicValueSerializers_property_valueSerializer_valueTypeSerializer

Constructor Summary

AccessConstructor 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 tools.jackson.databind.annotation.JsonSerialize#using), otherwise null
ser
,
AnnotatedMember accessor, Set<String> ignoredProperties)

protected
JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

True if method handled callbacks; false if not; in latter case caller will send default callbacks
_acceptJsonFormatVisitorForEnum
(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType)

Overridable helper method used for special case handling of schema information for Enums.

protected ValueSerializer<Object>
protected static ValueSerializer<Object>

Returns:

Configured serializer with specified properties ignored
_withIgnoreProperties
(ValueSerializer<?>
Serializer to be configured
ser
,
Set<String>
Properties to ignore, if any
ignoredProperties
)

Internal helper that configures the provided ser to ignore properties specified by JsonIgnoreProperties.

public void
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.jackson.databind.ValueSerializer.createContextual.

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.jackson.databind.ValueSerializer.isEmpty.

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.jackson.databind.ser.std.StdSerializer.serialize.

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.jackson.databind.ValueSerializer.serializeWithType.

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)

Inherited from tools.jackson.databind.ser.std.StdDynamicSerializer:
_findAndAddDynamic_findAndAddDynamic_findAndAddDynamic_findAndAddDynamic

Field Detail

_accessorback to summary
protected final AnnotatedMember _accessor

Accessor (field, getter) used to access value to serialize.

_forceTypeInformationback 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.

_ignoredPropertiesback to summary
protected final Set<String> _ignoredProperties
_staticTypingback to summary
protected final boolean _staticTyping
_valueTypeback to summary
protected final JavaType _valueType

Value for annotated accessor.

Constructor Detail

JsonValueSerializerback to summary
protected JsonValueSerializer(JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor, Set<String> ignoredProperties)
Parameters
ser:ValueSerializer<?>

Explicit serializer to use, if caller knows it (which occurs if and only if the "value method" was annotated with tools.jackson.databind.annotation.JsonSerialize#using), otherwise null

JsonValueSerializerback to summary
protected JsonValueSerializer(JsonValueSerializer src, BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)

Method Detail

_acceptJsonFormatVisitorForEnumback to summary
protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType)

Overridable helper method used for special case handling of schema information for Enums.

Returns:boolean

True if method handled callbacks; false if not; in latter case caller will send default callbacks

_findSerializerback to summary
protected ValueSerializer<Object> _findSerializer(SerializationContext ctxt, Object value)
_withIgnorePropertiesback to summary
protected static ValueSerializer<Object> _withIgnoreProperties(ValueSerializer<?> ser, Set<String> ignoredProperties)

Internal helper that configures the provided ser to ignore properties specified by JsonIgnoreProperties.

Parameters
ser:ValueSerializer<?>

Serializer to be configured

ignoredProperties:Set<String>

Properties to ignore, if any

Returns:ValueSerializer<Object>

Configured serializer with specified properties ignored

Annotations
@SuppressWarnings:unchecked
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)

Overrides tools.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from tools.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Default implementation specifies no format. This behavior is usually overriden by custom serializers.

Annotations
@Override
constructback to summary
public static JsonValueSerializer construct(SerializationConfig config, JavaType nominalType, JavaType valueType, boolean staticTyping, TypeSerializer vts, ValueSerializer<?> ser, AnnotatedMember accessor)
createContextualback to summary
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ValueSerializer.createContextual.

We can try to find the actual serializer for value, if we can statically figure out what the result type must be.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty(SerializationContext ctxt, Object bean)

Overrides tools.jackson.databind.ValueSerializer.isEmpty.

Doc from tools.jackson.databind.ValueSerializer.isEmpty.

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.

Annotations
@Override
isNaturalTypeWithStdHandlingback to summary
protected boolean isNaturalTypeWithStdHandling(Class<?> rawType, ValueSerializer<?> ser)
serializeback to summary
public void serialize(final Object bean, final JsonGenerator gen, final SerializationContext ctxt) throws JacksonException

Implements abstract tools.jackson.databind.ser.std.StdSerializer.serialize.

Doc from tools.jackson.databind.ValueSerializer.serialize.

Method that can be called to ask implementation to serialize values of type this serializer handles.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(Object bean, JsonGenerator gen, SerializationContext ctxt, TypeSerializer typeSer0) throws JacksonException

Overrides tools.jackson.databind.ValueSerializer.serializeWithType.

Doc from tools.jackson.databind.ValueSerializer.serializeWithType.

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 UnsupportedOperationException to 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, as START-ARRAY/END-ARRAY and START-OBJECT/END-OBJECT pairs need to be properly handled with respect to serializing of contents.
Annotations
@Override
withResolvedback to summary
public JsonValueSerializer withResolved(BeanProperty property, TypeSerializer vts, ValueSerializer<?> ser, boolean forceTypeInfo)
tools.jackson.databind.ser.jackson back to summary

pack-priv Class JsonValueSerializer.TypeSerializerRerouter

extends TypeSerializer
Class Inheritance

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)

Field Summary

Modifier and TypeField and Description
protected final Object
protected final TypeSerializer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public TypeSerializer
forProperty(SerializationContext ctxt, BeanProperty prop)

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.forProperty.

Method called to create contextual version, to be used for values of given property.

public String
getPropertyName()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getPropertyName.

Name of property that contains type information, if property-based inclusion is used.

public TypeIdResolver
getTypeIdResolver()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getTypeIdResolver.

Accessor for object that handles conversions between types and matching type ids.

public JsonTypeInfo.As
getTypeInclusion()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getTypeInclusion.

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.jackson.databind.jsontype.TypeSerializer.writeTypePrefix.

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.jackson.databind.jsontype.TypeSerializer.writeTypeSuffix.

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 writeTypePrefix(...).

Inherited from tools.jackson.databind.jsontype.TypeSerializer:
typeIdtypeIdtypeId

Field Detail

_forObjectback to summary
protected final Object _forObject
_typeSerializerback to summary
protected final TypeSerializer _typeSerializer

Constructor Detail

TypeSerializerRerouterback to summary
public TypeSerializerRerouter(TypeSerializer ts, Object ob)

Method Detail

forPropertyback to summary
public TypeSerializer forProperty(SerializationContext ctxt, BeanProperty prop)

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.forProperty.

Doc from tools.jackson.databind.jsontype.TypeSerializer.forProperty.

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 java.util.Collection or java.util.Map valued properties).

Note

since 3.0 has received context object as first argument.

Annotations
@Override
getPropertyNameback to summary
public String getPropertyName()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getPropertyName.

Doc from tools.jackson.databind.jsontype.TypeSerializer.getPropertyName.

Name of property that contains type information, if property-based inclusion is used.

Annotations
@Override
getTypeIdResolverback to summary
public TypeIdResolver getTypeIdResolver()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getTypeIdResolver.

Doc from tools.jackson.databind.jsontype.TypeSerializer.getTypeIdResolver.

Accessor for object that handles conversions between types and matching type ids.

Annotations
@Override
getTypeInclusionback to summary
public JsonTypeInfo.As getTypeInclusion()

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.getTypeInclusion.

Doc from tools.jackson.databind.jsontype.TypeSerializer.getTypeInclusion.

Accessor for type information inclusion method that serializer uses; indicates how type information is embedded in resulting JSON.

Annotations
@Override
writeTypePrefixback to summary
public WritableTypeId writeTypePrefix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId) throws JacksonException

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.writeTypePrefix.

Doc from tools.jackson.databind.jsontype.TypeSerializer.writeTypePrefix.

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.

Annotations
@Override
writeTypeSuffixback to summary
public WritableTypeId writeTypeSuffix(JsonGenerator g, SerializationContext ctxt, WritableTypeId typeId) throws JacksonException

Implements abstract tools.jackson.databind.jsontype.TypeSerializer.writeTypeSuffix.

Doc from tools.jackson.databind.jsontype.TypeSerializer.writeTypeSuffix.

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 writeTypePrefix(...).

Annotations
@Override