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

public Class MapSerializer

extends StdContainerSerializer<Map<?, ?>>
Class Inheritance
Annotations
@JacksonStdImpl
Imports
java.util.*, com.fasterxml.jackson.annotation.JsonFormat, .JsonInclude, 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, .JsonMapFormatVisitor, tools.jackson.databind.jsontype.TypeSerializer, tools.jackson.databind.ser.PropertyFilter, tools.jackson.databind.ser.std.StdContainerSerializer, tools.jackson.databind.type.TypeFactory, tools.jackson.databind.util.ArrayBuilders, .BeanUtil, .ClassUtil, .IgnorePropertiesUtil

Standard serializer implementation for serializing {link java.util.Map} types.

Note

about the only configurable setting currently is ability to filter out entries with specified names.

Field Summary

Modifier and TypeField and Description
protected final Object
_filterId

Id of the property filter to use, if any; null if none.

protected final Set<String>
_ignoredEntries

Set of entries to omit during serialization, if any

protected final Set<String>
_includedEntries

Set of entries to include during serialization, if null, it is ignored, empty will include nothing.

protected final IgnorePropertiesUtil.Checker
_inclusionChecker

Helper object used for name-based filtering

protected ValueSerializer<Object>
_keySerializer

Key serializer to use, if it can be statically determined

protected final JavaType
_keyType

Declared type of keys

protected final boolean
_sortKeys

Flag set if output is forced to be sorted by keys (usually due to annotation).

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 ValueSerializer<Object>
_valueSerializer

Value serializer to use, if it can be statically determined

protected final JavaType
_valueType

Declared type of contained values

protected final boolean
_valueTypeIsStatic

Whether static types should be used for serialization of values or not (if not, dynamic runtime type is used)

protected final TypeSerializer
_valueTypeSerializer

Type identifier serializer used for values, if any.

public static final Object
protected static final JavaType
Inherited from tools.jackson.databind.ser.std.StdContainerSerializer:
_dynamicValueSerializers_property

Constructor Summary

AccessConstructor and Description
protected
MapSerializer(Set<String> ignoredEntries, Set<String> includedEntries, JavaType keyType, JavaType valueType, boolean valueTypeIsStatic, TypeSerializer vts, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer)

protected
MapSerializer(MapSerializer src, BeanProperty property, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer, Set<String> ignoredEntries, Set<String> includedEntries)

protected
MapSerializer(MapSerializer src, TypeSerializer vts, Object suppressableValue, boolean suppressNulls)

protected
MapSerializer(MapSerializer src, Object filterId, boolean sortKeys)

Method Summary

Modifier and TypeMethod and Description
protected void
private final ValueSerializer<Object>
protected boolean
_hasNullKey(Map<?, ?> input)

protected Map<?, ?>
protected MapSerializer
_withValueTypeSerializer(TypeSerializer vts)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer._withValueTypeSerializer.

Method that needs to be implemented to allow construction of a new serializer object with given TypeSerializer, used when addition type information is to be embedded.

protected void
public void
public static MapSerializer
construct(JavaType mapType, boolean staticValueType, TypeSerializer vts, ValueSerializer<Object> keySerializer, ValueSerializer<Object> valueSerializer, Object filterId, Set<String> ignoredEntries, Set<String> includedEntries)

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 ValueSerializer<?>
getContentSerializer()

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.getContentSerializer.

Accessor for serializer used for serializing contents (List and array elements, Map values etc) of the container for which this serializer is used, if it is known statically.

public JavaType
getContentType()

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.getContentType.

Accessor for finding declared (static) element type for type this serializer is used for.

public ValueSerializer<?>
getKeySerializer()

Accessor for currently assigned key serializer.

public boolean
hasSingleElement(Map<?, ?> value)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.hasSingleElement.

Method called to determine if the given value (of type handled by this serializer) contains exactly one element.

public boolean
isEmpty(SerializationContext prov, Map<?, ?> value)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.isEmpty.

Method called to check whether given serializable value is considered "empty" value (for purposes of suppressing serialization of empty values).

public void
serialize(Map<?, ?> value, JsonGenerator gen, 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
serializeEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider)

General-purpose serialization for contents, where we do not necessarily know the value serialization, but we do know that no value suppression is needed (which simplifies processing a bit)

Note

public only because it is called by code from Guava TableSerializer

public void
serializeEntriesUsing(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, ValueSerializer<Object> ser)

Method called to serialize fields, when the value type is statically known, so that value serializer is passed and does not need to be fetched from provider.

public void
serializeFilteredAnyProperties(SerializationContext provider, JsonGenerator gen, Object
Enclosing POJO that has any-getter used to obtain "any properties"
bean
,
Map<?, ?> value, PropertyFilter filter, Object suppressableValue)

Helper method used when we have a JSON Filter to use AND contents are "any properties" of a POJO.

public void
serializeFilteredEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, PropertyFilter filter, Object suppressableValue)

Helper method used when we have a JSON Filter to use for potentially filtering out Map entries.

public void
serializeOptionalFields(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, Object suppressableValue)

Serialization method called when exclusion filtering needs to be applied.

public void
serializeTypedEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, Object suppressableValue)

Note

public because other similar methods are (no current known external usage).

public void
serializeWithoutTypeInfo(Map<?, ?> value, JsonGenerator gen, SerializationContext ctxt)

General-purpose serialization for contents without writing object type.

public void
serializeWithType(Map<?, ?> value, JsonGenerator gen, SerializationContext ctxt, 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 MapSerializer
withContentInclusion(Object suppressableValue, boolean suppressNulls)

Mutant factory for constructing an instance with different inclusion strategy for content (Map values).

public MapSerializer
withFilterId(Object filterId)

Overrides tools.jackson.databind.ValueSerializer.withFilterId.

Mutant factory method that is called if contextual configuration indicates that a specific filter (as specified by filterId) is to be used for serialization.

protected MapSerializer
withResolved(BeanProperty property, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer, Set<String> ignored, Set<String> included, boolean sortKeys)

Inherited from tools.jackson.databind.ser.std.StdContainerSerializer:
_findAndAddDynamic_findAndAddDynamicwithValueTypeSerializer

Field Detail

_filterIdback to summary
protected final Object _filterId

Id of the property filter to use, if any; null if none.

_ignoredEntriesback to summary
protected final Set<String> _ignoredEntries

Set of entries to omit during serialization, if any

_includedEntriesback to summary
protected final Set<String> _includedEntries

Set of entries to include during serialization, if null, it is ignored, empty will include nothing.

Since
2.12
_inclusionCheckerback to summary
protected final IgnorePropertiesUtil.Checker _inclusionChecker

Helper object used for name-based filtering

Since
2.12
_keySerializerback to summary
protected ValueSerializer<Object> _keySerializer

Key serializer to use, if it can be statically determined

_keyTypeback to summary
protected final JavaType _keyType

Declared type of keys

_sortKeysback to summary
protected final boolean _sortKeys

Flag set if output is forced to be sorted by keys (usually due to annotation).

_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

_valueSerializerback to summary
protected ValueSerializer<Object> _valueSerializer

Value serializer to use, if it can be statically determined

_valueTypeback to summary
protected final JavaType _valueType

Declared type of contained values

_valueTypeIsStaticback to summary
protected final boolean _valueTypeIsStatic

Whether static types should be used for serialization of values or not (if not, dynamic runtime type is used)

_valueTypeSerializerback to summary
protected final TypeSerializer _valueTypeSerializer

Type identifier serializer used for values, if any.

MARKER_FOR_EMPTYback to summary
public static final Object MARKER_FOR_EMPTY
UNSPECIFIED_TYPEback to summary
protected static final JavaType UNSPECIFIED_TYPE

Constructor Detail

MapSerializerback to summary
protected MapSerializer(Set<String> ignoredEntries, Set<String> includedEntries, JavaType keyType, JavaType valueType, boolean valueTypeIsStatic, TypeSerializer vts, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer)
Annotations
@SuppressWarnings:unchecked
MapSerializerback to summary
protected MapSerializer(MapSerializer src, BeanProperty property, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer, Set<String> ignoredEntries, Set<String> includedEntries)
Annotations
@SuppressWarnings:unchecked
MapSerializerback to summary
protected MapSerializer(MapSerializer src, TypeSerializer vts, Object suppressableValue, boolean suppressNulls)
MapSerializerback to summary
protected MapSerializer(MapSerializer src, Object filterId, boolean sortKeys)

Method Detail

_ensureOverrideback to summary
protected void _ensureOverride(String method)
_findSerializerback to summary
private final ValueSerializer<Object> _findSerializer(SerializationContext ctxt, Object value)
_hasNullKeyback to summary
protected boolean _hasNullKey(Map<?, ?> input)
_orderEntriesback to summary
protected Map<?, ?> _orderEntries(Map<?, ?> input, JsonGenerator gen, SerializationContext provider) throws JacksonException
_withValueTypeSerializerback to summary
protected MapSerializer _withValueTypeSerializer(TypeSerializer vts)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer._withValueTypeSerializer.

Doc from tools.jackson.databind.ser.std.StdContainerSerializer._withValueTypeSerializer.

Method that needs to be implemented to allow construction of a new serializer object with given TypeSerializer, used when addition type information is to be embedded.

Annotations
@Override
_writeNullKeyedEntryback to summary
protected void _writeNullKeyedEntry(JsonGenerator g, SerializationContext ctxt, Object value) throws JacksonException
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 MapSerializer construct(JavaType mapType, boolean staticValueType, TypeSerializer vts, ValueSerializer<Object> keySerializer, ValueSerializer<Object> valueSerializer, Object filterId, Set<String> ignoredEntries, Set<String> includedEntries)
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
getContentSerializerback to summary
public ValueSerializer<?> getContentSerializer()

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.getContentSerializer.

Doc from tools.jackson.databind.ser.std.StdContainerSerializer.getContentSerializer.

Accessor for serializer used for serializing contents (List and array elements, Map values etc) of the container for which this serializer is used, if it is known statically. Note that for dynamic types this may return null; if so, caller has to instead use getContentType() and tools.jackson.databind.SerializationContext#findContentValueSerializer.

Annotations
@Override
getContentTypeback to summary
public JavaType getContentType()

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.getContentType.

Doc from tools.jackson.databind.ser.std.StdContainerSerializer.getContentType.

Accessor for finding declared (static) element type for type this serializer is used for.

Annotations
@Override
getKeySerializerback to summary
public ValueSerializer<?> getKeySerializer()

Accessor for currently assigned key serializer. Note that this may return null during construction of MapSerializer: depedencies are resolved during createContextual method (which can be overridden by custom implementations), but for some dynamic types, it is possible that serializer is only resolved during actual serialization.

hasSingleElementback to summary
public boolean hasSingleElement(Map<?, ?> value)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.hasSingleElement.

Doc from tools.jackson.databind.ser.std.StdContainerSerializer.hasSingleElement.

Method called to determine if the given value (of type handled by this serializer) contains exactly one element.

Note

although it might seem sensible to instead define something like "getElementCount()" method, this would not work well for containers that do not keep track of size (like linked lists may not).

Note, too, that this method is only called by serializer itself; and specifically is not used for non-array/collection types like Map or Map.Entry instances.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty(SerializationContext prov, Map<?, ?> value)

Implements abstract tools.jackson.databind.ser.std.StdContainerSerializer.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
serializeback to summary
public void serialize(Map<?, ?> value, JsonGenerator gen, 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
serializeEntriesback to summary
public void serializeEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider) throws JacksonException

General-purpose serialization for contents, where we do not necessarily know the value serialization, but we do know that no value suppression is needed (which simplifies processing a bit)

Note

public only because it is called by code from Guava TableSerializer

serializeEntriesUsingback to summary
public void serializeEntriesUsing(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, ValueSerializer<Object> ser) throws JacksonException

Method called to serialize fields, when the value type is statically known, so that value serializer is passed and does not need to be fetched from provider.

Note

public because other similar methods are (no current known external usage).

serializeFilteredAnyPropertiesback to summary
public void serializeFilteredAnyProperties(SerializationContext provider, JsonGenerator gen, Object bean, Map<?, ?> value, PropertyFilter filter, Object suppressableValue) throws JacksonException

Helper method used when we have a JSON Filter to use AND contents are "any properties" of a POJO.

Note

public only because it is called by AnyGetterWriter

Parameters
bean:Object

Enclosing POJO that has any-getter used to obtain "any properties"

serializeFilteredEntriesback to summary
public void serializeFilteredEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, PropertyFilter filter, Object suppressableValue) throws JacksonException

Helper method used when we have a JSON Filter to use for potentially filtering out Map entries.

Note

public because other similar methods are (no current known external usage).

serializeOptionalFieldsback to summary
public void serializeOptionalFields(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, Object suppressableValue) throws JacksonException

Serialization method called when exclusion filtering needs to be applied.

Note

public because other similar methods are (no current known external usage).

serializeTypedEntriesback to summary
public void serializeTypedEntries(Map<?, ?> value, JsonGenerator gen, SerializationContext provider, Object suppressableValue) throws JacksonException

Note

public because other similar methods are (no current known external usage).

serializeWithoutTypeInfoback to summary
public void serializeWithoutTypeInfo(Map<?, ?> value, JsonGenerator gen, SerializationContext ctxt) throws JacksonException

General-purpose serialization for contents without writing object type. Will suppress, filter and use custom serializers.

Note

Public only since it also is called by AnyGetterWriter.

serializeWithTypeback to summary
public void serializeWithType(Map<?, ?> value, JsonGenerator gen, SerializationContext ctxt, 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
withContentInclusionback to summary
public MapSerializer withContentInclusion(Object suppressableValue, boolean suppressNulls)

Mutant factory for constructing an instance with different inclusion strategy for content (Map values).

Note

only public because it is called by BasicSerializerFactory.

withFilterIdback to summary
public MapSerializer withFilterId(Object filterId)

Overrides tools.jackson.databind.ValueSerializer.withFilterId.

Doc from tools.jackson.databind.ValueSerializer.withFilterId.

Mutant factory method that is called if contextual configuration indicates that a specific filter (as specified by filterId) is to be used for serialization.

Default implementation simply returns this; sub-classes that do support filtering will need to create and return new instance if filter changes.

Annotations
@Override
withResolvedback to summary
protected MapSerializer withResolved(BeanProperty property, ValueSerializer<?> keySerializer, ValueSerializer<?> valueSerializer, Set<String> ignored, Set<String> included, boolean sortKeys)