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

public abstract Class ReferenceTypeSerializer<T>

extends StdDynamicSerializer<T>
Class Inheritance
Known Direct Subclasses
tools.jackson.databind.ext.jdk8.Jdk8OptionalSerializer, tools.jackson.databind.ser.jdk.AtomicReferenceSerializer
Imports
com.fasterxml.jackson.annotation.JsonInclude, tools.jackson.core.JacksonException, .JsonGenerator, tools.jackson.databind.*, tools.jackson.databind.annotation.JsonSerialize, tools.jackson.databind.introspect.Annotated, tools.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.type.ReferenceType, tools.jackson.databind.util.ArrayBuilders, .BeanUtil, .NameTransformer

Base implementation for values of ReferenceType. Implements most of functionality, only leaving couple of abstract methods for sub-classes to implement.

Field Summary

Modifier and TypeField and Description
protected final JavaType
_referredType

Value type

protected final Object
_suppressableValue

Value that indicates suppression mechanism to use for values contained; either "filter" (of which equals() is called), or marker value of MARKER_FOR_EMPTY, or null to indicate no filtering for non-null values.

protected final boolean
_suppressNulls

Flag that indicates what to do with `null` values, distinct from handling of _suppressableValue

protected final NameTransformer
_unwrapper

In case of unwrapping, need name transformer.

public static final Object
Inherited from tools.jackson.databind.ser.std.StdDynamicSerializer:
_dynamicValueSerializers_property_valueSerializer_valueTypeSerializer

Constructor Summary

AccessConstructor and Description
public
ReferenceTypeSerializer(ReferenceType fullType, boolean staticTyping, TypeSerializer vts, ValueSerializer<Object> ser)

protected
ReferenceTypeSerializer(ReferenceTypeSerializer<?> base, BeanProperty property, TypeSerializer vts, ValueSerializer<?> valueSer, NameTransformer unwrapper, Object suppressableValue, boolean suppressNulls)

Method Summary

Modifier and TypeMethod and Description
private final ValueSerializer<Object>
_findCachedSerializer(SerializationContext provider, Class<?> rawType)

Helper method that encapsulates logic of retrieving and caching required serializer.

private final ValueSerializer<Object>
protected abstract Object
_getReferenced(T value)

protected abstract Object
protected abstract boolean
_isValuePresent(T value)

Method called to see if there is a value present or not.

protected boolean
_useStatic(SerializationContext serializers, BeanProperty property, JavaType referredType)

public void
public ValueSerializer<?>
createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ValueSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed).

public JavaType
public boolean
isEmpty(SerializationContext provider, T value)

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

public boolean
isUnwrappingSerializer()

Overrides tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.

public void
serialize(T ref, JsonGenerator g, SerializationContext provider)

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(T ref, JsonGenerator g, SerializationContext provider, TypeSerializer typeSer)

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 ValueSerializer<T>
unwrappingSerializer(NameTransformer transformer)

Overrides tools.jackson.databind.ValueSerializer.unwrappingSerializer.

Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output).

public abstract ReferenceTypeSerializer<T>
withContentInclusion(Object suppressableValue, boolean suppressNulls)

Mutant factory method called to create a differently constructed instance, specifically with different exclusion rules for contained value.

protected abstract ReferenceTypeSerializer<T>
withResolved(BeanProperty prop, TypeSerializer vts, ValueSerializer<?> valueSer, NameTransformer unwrapper)

Mutant factory method called when changes are needed; should construct newly configured instance with new values as indicated.

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

Field Detail

_referredTypeback to summary
protected final JavaType _referredType

Value type

_suppressableValueback to summary
protected final Object _suppressableValue

Value that indicates suppression mechanism to use for values contained; either "filter" (of which equals() is called), or marker value of MARKER_FOR_EMPTY, or null to indicate no filtering for non-null values. Note that inclusion value for Map instance itself is handled by caller (POJO property that refers to the Map value).

_suppressNullsback to summary
protected final boolean _suppressNulls

Flag that indicates what to do with `null` values, distinct from handling of _suppressableValue

_unwrapperback to summary
protected final NameTransformer _unwrapper

In case of unwrapping, need name transformer.

MARKER_FOR_EMPTYback to summary
public static final Object MARKER_FOR_EMPTY

Constructor Detail

ReferenceTypeSerializerback to summary
public ReferenceTypeSerializer(ReferenceType fullType, boolean staticTyping, TypeSerializer vts, ValueSerializer<Object> ser)
ReferenceTypeSerializerback to summary
protected ReferenceTypeSerializer(ReferenceTypeSerializer<?> base, BeanProperty property, TypeSerializer vts, ValueSerializer<?> valueSer, NameTransformer unwrapper, Object suppressableValue, boolean suppressNulls)

Method Detail

_findCachedSerializerback to summary
private final ValueSerializer<Object> _findCachedSerializer(SerializationContext provider, Class<?> rawType)

Helper method that encapsulates logic of retrieving and caching required serializer.

_findSerializerback to summary
private final ValueSerializer<Object> _findSerializer(SerializationContext provider, JavaType type, BeanProperty prop)
_getReferencedback to summary
protected abstract Object _getReferenced(T value)
_getReferencedIfPresentback to summary
protected abstract Object _getReferencedIfPresent(T value)
_isValuePresentback to summary
protected abstract boolean _isValuePresent(T value)

Method called to see if there is a value present or not. Note that value itself may still be `null`, even if present, if referential type allows three states (absent, present-null, present-non-null); some only allow two (absent, present-non-null).

_useStaticback to summary
protected boolean _useStatic(SerializationContext serializers, BeanProperty property, JavaType referredType)
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
createContextualback to summary
public ValueSerializer<?> createContextual(SerializationContext ctxt, BeanProperty property)

Overrides tools.jackson.databind.ValueSerializer.createContextual.

Doc from tools.jackson.databind.ValueSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property (or, for root values, in which case `null` is passed). Note that instance that this method is called on is typically shared one and as a result method should NOT modify this instance but rather construct and return a new instance. This instance should only be returned as-is, in case it is already suitable for use.

Note that method is only called once per POJO property, and for the first usage as root value serializer; it is not called for every serialization, as doing that would have significant performance impact; most serializers cache contextual instances for future use.

Annotations
@Override
getReferredTypeback to summary
public JavaType getReferredType()
isEmptyback to summary
public boolean isEmpty(SerializationContext provider, T value) throws JacksonException

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
isUnwrappingSerializerback to summary
public boolean isUnwrappingSerializer()

Overrides tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Doc from tools.jackson.databind.ValueSerializer.isUnwrappingSerializer.

Accessor for checking whether this serializer is an "unwrapping" serializer; this is necessary to know since it may also require caller to suppress writing of the leading property name.

Annotations
@Override
serializeback to summary
public void serialize(T ref, JsonGenerator g, SerializationContext provider) 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(T ref, JsonGenerator g, SerializationContext provider, TypeSerializer typeSer) 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
unwrappingSerializerback to summary
public ValueSerializer<T> unwrappingSerializer(NameTransformer transformer)

Overrides tools.jackson.databind.ValueSerializer.unwrappingSerializer.

Doc from tools.jackson.databind.ValueSerializer.unwrappingSerializer.

Method that will return serializer instance that produces "unwrapped" serialization, if applicable for type being serialized (which is the case for some serializers that produce JSON Objects as output). If no unwrapped serializer can be constructed, will simply return serializer as-is.

Default implementation just returns serializer as-is, indicating that no unwrapped variant exists

Annotations
@Override
withContentInclusionback to summary
public abstract ReferenceTypeSerializer<T> withContentInclusion(Object suppressableValue, boolean suppressNulls)

Mutant factory method called to create a differently constructed instance, specifically with different exclusion rules for contained value.

Note

caller has verified that there are changes, so implementations need NOT check if a new instance is needed.

withResolvedback to summary
protected abstract ReferenceTypeSerializer<T> withResolved(BeanProperty prop, TypeSerializer vts, ValueSerializer<?> valueSer, NameTransformer unwrapper)

Mutant factory method called when changes are needed; should construct newly configured instance with new values as indicated.

Note

caller has verified that there are changes, so implementations need NOT check if a new instance is needed.