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

public final Enum SerializationFeature

extends Enum<SerializationFeature>
implements ConfigFeature
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.databind.cfg.ConfigFeature
Imports
com.fasterxml.jackson.databind.cfg.ConfigFeature, .EnumFeature

Enumeration that defines simple on/off features that affect the way Java objects are serialized.

Note that features can be set both through ObjectMapper (as sort of defaults) and through ObjectWriter. In first case these defaults must follow "config-then-use" patterns (i.e. defined once, not changed afterwards); all per-call changes must be done using ObjectWriter.

Field Summary

Modifier and TypeField and Description
private final boolean
private final int
public static final SerializationFeature
CLOSE_CLOSEABLE

Feature that determines whether close method of serialized root level objects (ones for which ObjectMapper's writeValue() (or equivalent) method is called) that implement java.io.Closeable is called after serialization or not.

public static final SerializationFeature
EAGER_SERIALIZER_FETCH

Feature that determines whether ObjectWriter should try to eagerly fetch necessary JsonSerializer when possible.

public static final SerializationFeature
FAIL_ON_EMPTY_BEANS

Feature that determines what happens when no accessors are found for a type (and there are no annotations to indicate it is meant to be serialized).

public static final SerializationFeature
FAIL_ON_SELF_REFERENCES

Feature that determines what happens when a direct self-reference is detected by a POJO (and no Object Id handling is enabled for it): either a JsonMappingException is thrown (if true), or reference is normally processed (false).

public static final SerializationFeature
FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS

Feature that determines what happens when an object which normally has type information included by Jackson is used in conjunction with com.fasterxml.jackson.annotation.JsonUnwrapped.

public static final SerializationFeature
FLUSH_AFTER_WRITE_VALUE

Feature that determines whether JsonGenerator.flush() is called after writeValue() method that takes JsonGenerator as an argument completes (i.e. does NOT affect methods that use other destinations); same for methods in ObjectWriter.

public static final SerializationFeature
INDENT_OUTPUT

Feature that allows enabling (or disabling) indentation for the underlying generator, using the default pretty printer configured for ObjectMapper (and ObjectWriters created from mapper).

public static final SerializationFeature
ORDER_MAP_ENTRIES_BY_KEYS

Feature that determines whether java.util.Map entries are first sorted by key before serialization or not: if enabled, additional sorting step is performed if necessary (not necessary for java.util.SortedMaps), if disabled, no additional sorting is needed.

public static final SerializationFeature
USE_EQUALITY_FOR_OBJECT_ID

Feature that determines whether Object Identity is compared using true JVM-level identity of Object (false); or, equals() method.

public static final SerializationFeature
WRAP_EXCEPTIONS

Feature that determines whether Jackson code should catch and wrap Exceptions (but never Errors!) to add additional information about location (within input) of problem or not.

public static final SerializationFeature
WRAP_ROOT_VALUE

Feature that can be enabled to make root value (usually JSON Object but can be any type) wrapped within a single property JSON object, where key as the "root name", as determined by annotation introspector (esp.

public static final SerializationFeature
WRITE_BIGDECIMAL_AS_PLAIN

Feature that determines whether java.math.BigDecimal entries are serialized using java.math.BigDecimal#toPlainString() to prevent values to be written using scientific notation.
public static final SerializationFeature
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS

Feature that determines how type char[] is serialized: when enabled, will be serialized as an explict JSON array (with single-character Strings as values); when disabled, defaults to serializing them as Strings (which is more compact).

public static final SerializationFeature
WRITE_DATE_KEYS_AS_TIMESTAMPS

Feature that determines whether java.util.Dates (and sub-types) used as java.util.Map keys are serialized as time stamps or not (if not, will be serialized as textual values).

public static final SerializationFeature
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS

Feature that controls whether numeric timestamp values are to be written using nanosecond timestamps (enabled) or not (disabled); if and only if datatype supports such resolution.

public static final SerializationFeature
WRITE_DATES_AS_TIMESTAMPS

Feature that determines whether Date (and date/time) values (and Date-based things like java.util.Calendars) are to be serialized as numeric time stamps (true; the default), or as something else (usually textual representation).

public static final SerializationFeature
WRITE_DATES_WITH_CONTEXT_TIME_ZONE

Feature that determines whether timezone/offset included in zoned date/time values (note: does NOT java.util.Date will be overridden if there is an explicitly set context time zone.

public static final SerializationFeature
WRITE_DATES_WITH_ZONE_ID

Feature that determines whether date/date-time values should be serialized so that they include timezone id, in cases where type itself contains timezone information.

public static final SerializationFeature
WRITE_DURATIONS_AS_TIMESTAMPS

Feature that determines whether time values that represents time periods (durations, periods, ranges) are to be serialized by default using a numeric (true) or textual (false) representations.

public static final SerializationFeature
WRITE_EMPTY_JSON_ARRAYS

Deprecated Since 2.8 there are better mechanism for specifying filtering; specifically using com.fasterxml.jackson.annotation.JsonInclude or configuration overrides.
Feature that determines whether Container properties (POJO properties with declared value of Collection or array; i.e. things that produce JSON arrays) that are empty (have no elements) will be serialized as empty JSON arrays (true), or suppressed from output (false).
public static final SerializationFeature
WRITE_ENUM_KEYS_USING_INDEX

Feature that determines whether {link Enum}s used as java.util.Map keys are serialized as using Enum#ordinal() or not.

public static final SerializationFeature
WRITE_ENUMS_USING_INDEX

Feature that determines whether Java Enum values are serialized as numbers (true), or textual values (false).

public static final SerializationFeature
WRITE_ENUMS_USING_TO_STRING

Feature that determines standard serialization mechanism used for Enum values: if enabled, return value of Enum.toString() is used; if disabled, return value of Enum.name() is used.

public static final SerializationFeature
WRITE_NULL_MAP_VALUES

Deprecated Since 2.9 there are better mechanism for specifying filtering; specifically using com.fasterxml.jackson.annotation.JsonInclude or configuration overrides (see ObjectMapper#configOverride(Class)}).
Feature that determines whether Map entries with null values are to be serialized (true) or not (false).
public static final SerializationFeature
WRITE_SELF_REFERENCES_AS_NULL

Feature that determines what happens when a direct self-reference is detected by a POJO (and no Object Id handling is enabled for it): if enabled write that reference as null; if disabled, default behavior is used (which will try to serialize usually resulting in exception).

public static final SerializationFeature
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED

Feature added for interoperability, to work with oddities of so-called "BadgerFish" convention.

Constructor Summary

AccessConstructor and Description
private
SerializationFeature(boolean defaultState)

Method Summary

Modifier and TypeMethod and Description
public boolean
enabledByDefault()

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledByDefault.

Accessor for checking whether this feature is enabled by default.

public boolean
enabledIn(int flags)

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledIn.

Convenience method for checking whether feature is enabled in given bitmask

public int
getMask()

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.getMask.

Returns bit mask for this feature instance

public static SerializationFeature
public static SerializationFeature[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

_defaultStateback to summary
private final boolean _defaultState
_maskback to summary
private final int _mask
CLOSE_CLOSEABLEback to summary
public static final SerializationFeature CLOSE_CLOSEABLE

Feature that determines whether close method of serialized root level objects (ones for which ObjectMapper's writeValue() (or equivalent) method is called) that implement java.io.Closeable is called after serialization or not. If enabled, close() will be called after serialization completes (whether succesfully, or due to an error manifested by an exception being thrown). You can think of this as sort of "finally" processing.

Note

only affects behavior with root objects, and not other objects reachable from the root object. Put another way, only one call will be made for each 'writeValue' call.

Feature is disabled by default.

EAGER_SERIALIZER_FETCHback to summary
public static final SerializationFeature EAGER_SERIALIZER_FETCH

Feature that determines whether ObjectWriter should try to eagerly fetch necessary JsonSerializer when possible. This improves performance in cases where similarly configured ObjectWriter instance is used multiple times; and should not significantly affect single-use cases.

Note that there should not be any need to normally disable this feature: only consider that if there are actual perceived problems.

Feature is enabled by default.

Since
2.1
FAIL_ON_EMPTY_BEANSback to summary
public static final SerializationFeature FAIL_ON_EMPTY_BEANS

Feature that determines what happens when no accessors are found for a type (and there are no annotations to indicate it is meant to be serialized). If enabled (default), an exception is thrown to indicate these as non-serializable types; if disabled, they are serialized as empty Objects, i.e. without any properties.

Note that empty types that this feature has only effect on those "empty" beans that do not have any recognized annotations (like @JsonSerialize): ones that do have annotations do not result in an exception being thrown.

Feature is enabled by default.

FAIL_ON_SELF_REFERENCESback to summary
public static final SerializationFeature FAIL_ON_SELF_REFERENCES

Feature that determines what happens when a direct self-reference is detected by a POJO (and no Object Id handling is enabled for it): either a JsonMappingException is thrown (if true), or reference is normally processed (false).

Feature is enabled by default.

Since
2.4
FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERSback to summary
public static final SerializationFeature FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS

Feature that determines what happens when an object which normally has type information included by Jackson is used in conjunction with com.fasterxml.jackson.annotation.JsonUnwrapped. In the default (enabled) state, an error will be thrown when an unwrapped object has type information. When disabled, the object will be unwrapped and the type information discarded.

Feature is enabled by default.

Since
2.4
FLUSH_AFTER_WRITE_VALUEback to summary
public static final SerializationFeature FLUSH_AFTER_WRITE_VALUE

Feature that determines whether JsonGenerator.flush() is called after writeValue() method that takes JsonGenerator as an argument completes (i.e. does NOT affect methods that use other destinations); same for methods in ObjectWriter. This usually makes sense; but there are cases where flushing should not be forced: for example when underlying stream is compressing and flush() causes compression state to be flushed (which occurs with some compression codecs).

Feature is enabled by default.

INDENT_OUTPUTback to summary
public static final SerializationFeature INDENT_OUTPUT

Feature that allows enabling (or disabling) indentation for the underlying generator, using the default pretty printer configured for ObjectMapper (and ObjectWriters created from mapper).

Note that the default pretty printer is only used if no explicit com.fasterxml.jackson.core.PrettyPrinter has been configured for the generator or ObjectWriter.

Feature is disabled by default.

ORDER_MAP_ENTRIES_BY_KEYSback to summary
public static final SerializationFeature ORDER_MAP_ENTRIES_BY_KEYS

Feature that determines whether java.util.Map entries are first sorted by key before serialization or not: if enabled, additional sorting step is performed if necessary (not necessary for java.util.SortedMaps), if disabled, no additional sorting is needed.

Feature is disabled by default.

USE_EQUALITY_FOR_OBJECT_IDback to summary
public static final SerializationFeature USE_EQUALITY_FOR_OBJECT_ID

Feature that determines whether Object Identity is compared using true JVM-level identity of Object (false); or, equals() method. Latter is sometimes useful when dealing with Database-bound objects with ORM libraries (like Hibernate). Note that Object itself is actually compared, and NOT Object Id; naming of this feature is somewhat confusing, so it is important that Object for which identity is to be preserved are considered equal, above and beyond ids (which are always compared using equality anyway).

Note

due to the way functionality is implemented, it is very important that in addition to overriding Object#equals for Objects to match (to be considered "same") it is also necessary to ensure that Object#hashCode() is overridden to produce the exact same value for equal instances.

Feature is disabled by default; meaning that strict identity is used, not equals()

Since
2.3
WRAP_EXCEPTIONSback to summary
public static final SerializationFeature WRAP_EXCEPTIONS

Feature that determines whether Jackson code should catch and wrap Exceptions (but never Errors!) to add additional information about location (within input) of problem or not. If enabled, most exceptions will be caught and re-thrown (exception specifically being that java.io.IOExceptions may be passed as is, since they are declared as throwable); this can be convenient both in that all exceptions will be checked and declared, and so there is more contextual information. However, sometimes calling application may just want "raw" unchecked exceptions passed as is.

Feature is enabled by default.

WRAP_ROOT_VALUEback to summary
public static final SerializationFeature WRAP_ROOT_VALUE

Feature that can be enabled to make root value (usually JSON Object but can be any type) wrapped within a single property JSON object, where key as the "root name", as determined by annotation introspector (esp. for JAXB that uses @XmlRootElement.name) or fallback (non-qualified class name). Feature is mostly intended for JAXB compatibility.

Feature is disabled by default.

WRITE_BIGDECIMAL_AS_PLAINback to summary
public static final SerializationFeature WRITE_BIGDECIMAL_AS_PLAIN

Feature that determines whether java.math.BigDecimal entries are serialized using java.math.BigDecimal#toPlainString() to prevent values to be written using scientific notation.

Note

since this feature typically requires use of com.fasterxml.jackson.core.JsonGenerator#writeNumber(String) it may cause compatibility problems since not all com.fasterxml.jackson.core.JsonGenerator implementations support such mode of output: usually only text-based formats support it.

Feature is disabled by default.

Annotations
@Deprecated
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYSback to summary
public static final SerializationFeature WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS

Feature that determines how type char[] is serialized: when enabled, will be serialized as an explict JSON array (with single-character Strings as values); when disabled, defaults to serializing them as Strings (which is more compact).

Feature is disabled by default.

WRITE_DATE_KEYS_AS_TIMESTAMPSback to summary
public static final SerializationFeature WRITE_DATE_KEYS_AS_TIMESTAMPS

Feature that determines whether java.util.Dates (and sub-types) used as java.util.Map keys are serialized as time stamps or not (if not, will be serialized as textual values).

Default value is 'false', meaning that Date-valued Map keys are serialized as textual (ISO-8601) values.

Feature is disabled by default.

WRITE_DATE_TIMESTAMPS_AS_NANOSECONDSback to summary
public static final SerializationFeature WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS

Feature that controls whether numeric timestamp values are to be written using nanosecond timestamps (enabled) or not (disabled); if and only if datatype supports such resolution. Only newer datatypes (such as Java8 Date/Time) support such resolution -- older types (pre-Java8 java.util.Date etc) and Joda do not -- and this setting has no effect on such types.

If disabled, standard millisecond timestamps are assumed. This is the counterpart to DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS.

Feature is enabled by default, to support most accurate time values possible.

Since
2.2
WRITE_DATES_AS_TIMESTAMPSback to summary
public static final SerializationFeature WRITE_DATES_AS_TIMESTAMPS

Feature that determines whether Date (and date/time) values (and Date-based things like java.util.Calendars) are to be serialized as numeric time stamps (true; the default), or as something else (usually textual representation). If textual representation is used, the actual format depends on configuration settings including possible per-property use of @JsonFormat annotation, globally configured java.text.DateFormat.

For "classic" JDK date types (java.util.Date, java.util.Calendar) the default formatting is provided by com.fasterxml.jackson.databind.util.StdDateFormat, and corresponds to format String of "yyyy-MM-dd'T'HH:mm:ss.SSSX" (see java.text.DateFormat for details of format Strings). Whether this feature affects handling of other date-related types depend on handlers of those types, although ideally they should use this feature

Note

whether java.util.Map keys are serialized as Strings or not is controlled using WRITE_DATE_KEYS_AS_TIMESTAMPS instead of this feature.

Feature is enabled by default, so that date/time are by default serialized as time stamps.

WRITE_DATES_WITH_CONTEXT_TIME_ZONEback to summary
public static final SerializationFeature WRITE_DATES_WITH_CONTEXT_TIME_ZONE

Feature that determines whether timezone/offset included in zoned date/time values (note: does NOT java.util.Date will be overridden if there is an explicitly set context time zone. If disabled, timezone/offset value is used-is; if enabled, context time zone is used instead.

Note that this setting only affects "Zoned" date/time values of Java 8 date/time types -- it will have no effect on old java.util value handling (of which java.util.Date has no timezone information and must use contextual timezone, implicit or explicit; and java.util.Calendar which will always use timezone Calendar value has). Setting is also ignored by Joda date/time values.

Feature is enabled by default for backwards-compatibility purposes (in Jackson 2.12 override was always done if there was explicitly defined timezone).

Since
2.13
WRITE_DATES_WITH_ZONE_IDback to summary
public static final SerializationFeature WRITE_DATES_WITH_ZONE_ID

Feature that determines whether date/date-time values should be serialized so that they include timezone id, in cases where type itself contains timezone information. Including this information may lead to compatibility issues because ISO-8601 specification does not define formats that include such information.

If enabled, Timezone id should be included using format specified with Java 8 DateTimeFormatter#ISO_ZONED_DATE_TIME definition (for example, '2011-12-03T10:15:30+01:00[Europe/Paris]').

Note

setting has no relevance if date/time values are serialized as timestamps.

Feature is disabled by default, so that zone id is NOT included; rather, timezone offset is used for ISO-8601 compatibility (if any timezone information is included in value).

Since
2.6
WRITE_DURATIONS_AS_TIMESTAMPSback to summary
public static final SerializationFeature WRITE_DURATIONS_AS_TIMESTAMPS

Feature that determines whether time values that represents time periods (durations, periods, ranges) are to be serialized by default using a numeric (true) or textual (false) representations. Note that numeric representation may mean either simple number, or an array of numbers, depending on type.

Note

whether java.util.Map keys are serialized as Strings or not is controlled using WRITE_DATE_KEYS_AS_TIMESTAMPS.

Feature is enabled by default, so that period/duration are by default serialized as timestamps.

Since
2.5
WRITE_EMPTY_JSON_ARRAYSback to summary
public static final SerializationFeature WRITE_EMPTY_JSON_ARRAYS

Deprecated

Since 2.8 there are better mechanism for specifying filtering; specifically using com.fasterxml.jackson.annotation.JsonInclude or configuration overrides.

Feature that determines whether Container properties (POJO properties with declared value of Collection or array; i.e. things that produce JSON arrays) that are empty (have no elements) will be serialized as empty JSON arrays (true), or suppressed from output (false).

Note that this does not change behavior of java.util.Maps, or "Collection-like" types.

Note

unlike other SerializationFeatures, this feature cannot be dynamically changed on per-call basis, because its effect is considered during construction of serializers and property handlers.

Feature is enabled by default.

Annotations
@Deprecated
WRITE_ENUM_KEYS_USING_INDEXback to summary
public static final SerializationFeature WRITE_ENUM_KEYS_USING_INDEX

Feature that determines whether {link Enum}s used as java.util.Map keys are serialized as using Enum#ordinal() or not. Similar to WRITE_ENUMS_USING_INDEX used when writing Enums as regular values.

Note

counterpart for this settings is EnumFeature#READ_ENUM_KEYS_USING_INDEX.

Feature is disabled by default.

Since
2.10
WRITE_ENUMS_USING_INDEXback to summary
public static final SerializationFeature WRITE_ENUMS_USING_INDEX

Feature that determines whether Java Enum values are serialized as numbers (true), or textual values (false). If textual values are used, other settings are also considered. If this feature is enabled, return value of Enum.ordinal() (an integer) will be used as the serialization.

Note that this feature has precedence over WRITE_ENUMS_USING_TO_STRING, which is only considered if this feature is set to false.

Note that since 2.10, this does NOT apply to Enums written as keys of java.util.Map values, which has separate setting, WRITE_ENUM_KEYS_USING_INDEX.

Feature is disabled by default.

WRITE_ENUMS_USING_TO_STRINGback to summary
public static final SerializationFeature WRITE_ENUMS_USING_TO_STRING

Feature that determines standard serialization mechanism used for Enum values: if enabled, return value of Enum.toString() is used; if disabled, return value of Enum.name() is used.

Note

this feature should usually have same value as DeserializationFeature#READ_ENUMS_USING_TO_STRING.

Feature is disabled by default.

WRITE_NULL_MAP_VALUESback to summary
public static final SerializationFeature WRITE_NULL_MAP_VALUES

Deprecated

Since 2.9 there are better mechanism for specifying filtering; specifically using com.fasterxml.jackson.annotation.JsonInclude or configuration overrides (see ObjectMapper#configOverride(Class)}).

Feature that determines whether Map entries with null values are to be serialized (true) or not (false).

Note

unlike other SerializationFeatures, this feature cannot be dynamically changed on per-call basis, because its effect is considered during construction of serializers and property handlers.

Feature is enabled by default.

Annotations
@Deprecated
WRITE_SELF_REFERENCES_AS_NULLback to summary
public static final SerializationFeature WRITE_SELF_REFERENCES_AS_NULL

Feature that determines what happens when a direct self-reference is detected by a POJO (and no Object Id handling is enabled for it): if enabled write that reference as null; if disabled, default behavior is used (which will try to serialize usually resulting in exception). But if SerializationFeature#FAIL_ON_SELF_REFERENCES is enabled. this property is ignored.

Feature is disabled by default.

Since
2.11
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPEDback to summary
public static final SerializationFeature WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED

Feature added for interoperability, to work with oddities of so-called "BadgerFish" convention. Feature determines handling of single element java.util.Collections and arrays: if enabled, java.util.Collections and arrays that contain exactly one element will be serialized as if that element itself was serialized.

When enabled, a POJO with array that normally looks like this:

  { "arrayProperty" : [ 1 ] }
will instead be serialized as
  { "arrayProperty" : 1 }

Note that this feature is counterpart to DeserializationFeature#ACCEPT_SINGLE_VALUE_AS_ARRAY (that is, usually both are enabled, or neither is).

Feature is disabled by default, so that no special handling is done.

Constructor Detail

SerializationFeatureback to summary
private SerializationFeature(boolean defaultState)

Method Detail

enabledByDefaultback to summary
public boolean enabledByDefault()

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledByDefault.

Doc from com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledByDefault.

Accessor for checking whether this feature is enabled by default.

Annotations
@Override
enabledInback to summary
public boolean enabledIn(int flags)

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledIn.

Doc from com.fasterxml.jackson.databind.cfg.ConfigFeature.enabledIn.

Convenience method for checking whether feature is enabled in given bitmask

Annotations
@Override
getMaskback to summary
public int getMask()

Implements com.fasterxml.jackson.databind.cfg.ConfigFeature.getMask.

Doc from com.fasterxml.jackson.databind.cfg.ConfigFeature.getMask.

Returns bit mask for this feature instance

Annotations
@Override
valueOfback to summary
public static SerializationFeature valueOf(String name)
valuesback to summary
public static SerializationFeature[] values()