Top Description Fields Constructors Methods
com.fasterxml.jackson.databind.ser.std

public abstract Class ReferenceTypeSerializer<T>

extends StdSerializer<T>
implements ContextualSerializer
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.ser.ContextualSerializer
Known Direct Subclasses
com.fasterxml.jackson.databind.ser.std.AtomicReferenceSerializer
Imports
java.io.IOException, com.fasterxml.jackson.annotation.JsonInclude, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.*, com.fasterxml.jackson.databind.annotation.JsonSerialize, com.fasterxml.jackson.databind.introspect.Annotated, com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper, com.fasterxml.jackson.databind.jsontype.TypeSerializer, com.fasterxml.jackson.databind.ser.ContextualSerializer, com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap, com.fasterxml.jackson.databind.type.ReferenceType, com.fasterxml.jackson.databind.util.ArrayBuilders, .BeanUtil, .NameTransformer

References Deprecated

StdSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Field Summary

Modifier and TypeField and Description
protected transient PropertySerializerMap
_dynamicSerializers

If element type cannot be statically determined, mapping from runtime type to serializer is handled using this object

protected final BeanProperty
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.

protected final JsonSerializer<Object>
_valueSerializer

Serializer for content values, if statically known.

protected final TypeSerializer
_valueTypeSerializer

Type serializer used for values, if any.

public static final Object
private static final long
Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_handledType

Constructor Summary

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

protected
ReferenceTypeSerializer(ReferenceTypeSerializer<?> base, BeanProperty property, TypeSerializer vts, JsonSerializer<?> valueSer, NameTransformer unwrapper, Object suppressableValue, boolean suppressNulls)
References Deprecated ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

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

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

private final JsonSerializer<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(SerializerProvider provider, BeanProperty property, JavaType referredType)

public void
public JsonSerializer<?>
createContextual(SerializerProvider
Serializer provider to use for accessing config, other serializers
provider
,
BeanProperty
Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)
property
)

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property.

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

Overrides com.fasterxml.jackson.databind.JsonSerializer.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 com.fasterxml.jackson.databind.JsonSerializer.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
Value to serialize; can not be null.
ref
,
JsonGenerator
Generator used to output resulting Json content
g
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
)

Implements abstract com.fasterxml.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
Value to serialize; can not be null.
ref
,
JsonGenerator
Generator used to output resulting Json content
g
,
SerializerProvider
Provider that can be used to get serializers for serializing Objects value contains, if any.
provider
,
TypeSerializer
Type serializer to use for including type information
typeSer
)

Overrides com.fasterxml.jackson.databind.JsonSerializer.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 JsonSerializer<T>
unwrappingSerializer(NameTransformer
Name transformation to use to convert between names of unwrapper properties
transformer
)

Overrides com.fasterxml.jackson.databind.JsonSerializer.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)
References Deprecated ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

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, JsonSerializer<?> valueSer, NameTransformer unwrapper)
References Deprecated ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

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

Inherited from com.fasterxml.jackson.databind.ser.std.StdSerializer:
_neitherNull_nonEmptycreateSchemaNodecreateSchemaNodefindAnnotatedContentSerializerfindContextualConvertingSerializerfindConvertingContentSerializerfindFormatFeaturefindFormatOverridesfindIncludeOverridesfindPropertyFiltergetSchemagetSchemahandledTypeisDefaultSerializervisitArrayFormatvisitArrayFormatvisitFloatFormatvisitIntFormatvisitIntFormatvisitStringFormatvisitStringFormatwrapAndThrowwrapAndThrow

Field Detail

_dynamicSerializersback to summary
protected transient PropertySerializerMap _dynamicSerializers

If element type cannot be statically determined, mapping from runtime type to serializer is handled using this object

_propertyback to summary
protected final BeanProperty _property
_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).

Since
2.9
_suppressNullsback to summary
protected final boolean _suppressNulls

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

Since
2.9
_unwrapperback to summary
protected final NameTransformer _unwrapper

In case of unwrapping, need name transformer.

_valueSerializerback to summary
protected final JsonSerializer<Object> _valueSerializer

Serializer for content values, if statically known.

_valueTypeSerializerback to summary
protected final TypeSerializer _valueTypeSerializer

Type serializer used for values, if any.

MARKER_FOR_EMPTYback to summary
public static final Object MARKER_FOR_EMPTY
Since
2.9
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.fasterxml.jackson.databind.ser.std.StdSerializer.serialVersionUID.

Constructor Detail

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

References Deprecated

ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Annotations
@SuppressWarnings:unchecked

Method Detail

_findCachedSerializerback to summary
private final JsonSerializer<Object> _findCachedSerializer(SerializerProvider provider, Class<?> rawType) throws JsonMappingException

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

_findSerializerback to summary
private final JsonSerializer<Object> _findSerializer(SerializerProvider provider, JavaType type, BeanProperty prop) throws JsonMappingException
_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(SerializerProvider provider, BeanProperty property, JavaType referredType)
acceptJsonFormatVisitorback to summary
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException

Overrides com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

Implements com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Doc from com.fasterxml.jackson.databind.ser.std.StdSerializer.acceptJsonFormatVisitor.

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

Parameters
typeHint:JavaType

Doc from com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable.acceptJsonFormatVisitor.

Type of element (entity like property) being visited

Annotations
@Override
createContextualback to summary
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException

Implements com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Doc from com.fasterxml.jackson.databind.ser.ContextualSerializer.createContextual.

Method called to see if a different (or differently configured) serializer is needed to serialize values of specified property. 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.

Parameters
provider:SerializerProvider

Serializer provider to use for accessing config, other serializers

property:BeanProperty

Method or field that represents the property (and is used to access value to serialize). Should be available; but there may be cases where caller cannot provide it and null is passed instead (in which case impls usually pass 'this' serializer as is)

Returns:JsonSerializer<?>

Serializer to use for serializing values of specified property; may be this instance or a new instance.

Annotations
@Override
getReferredTypeback to summary
public JavaType getReferredType()
Since
2.9
isEmptyback to summary
public boolean isEmpty(SerializerProvider provider, T value)

Overrides com.fasterxml.jackson.databind.JsonSerializer.isEmpty.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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.

Note

replaces isEmpty(Object), which was deprecated in 2.5

Annotations
@Override
isUnwrappingSerializerback to summary
public boolean isUnwrappingSerializer()

Overrides com.fasterxml.jackson.databind.JsonSerializer.isUnwrappingSerializer.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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, SerializerProvider provider) throws IOException

Implements abstract com.fasterxml.jackson.databind.ser.std.StdSerializer.serialize.

Doc from com.fasterxml.jackson.databind.JsonSerializer.serialize.

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

Parameters
ref:T

Value to serialize; can not be null.

g:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

Annotations
@Override
serializeWithTypeback to summary
public void serializeWithType(T ref, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException

Overrides com.fasterxml.jackson.databind.JsonSerializer.serializeWithType.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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.
Parameters
ref:T

Value to serialize; can not be null.

g:JsonGenerator

Generator used to output resulting Json content

provider:SerializerProvider

Provider that can be used to get serializers for serializing Objects value contains, if any.

typeSer:TypeSerializer

Type serializer to use for including type information

Annotations
@Override
unwrappingSerializerback to summary
public JsonSerializer<T> unwrappingSerializer(NameTransformer transformer)

Overrides com.fasterxml.jackson.databind.JsonSerializer.unwrappingSerializer.

Doc from com.fasterxml.jackson.databind.JsonSerializer.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

Parameters
transformer:NameTransformer

Name transformation to use to convert between names of unwrapper properties

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

References Deprecated

ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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.

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

References Deprecated

ReferenceTypeSerializer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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.

Since
2.9