com.fasterxml.jackson.databind

## Enum SerializationFeature

- java.lang.Object
- - java.lang.Enum<SerializationFeature>
  - - com.fasterxml.jackson.databind.SerializationFeature

All Implemented Interfaces:
  ConfigFeature, Serializable, Comparable<SerializationFeature>

    public enum SerializationFeature
    extends Enum<SerializationFeature>
    implements ConfigFeature

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

### Enum Constant Summary

Enum Constants
Enum Constant and Description
`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 `Closeable` is called after serialization or not.
`EAGER_SERIALIZER_FETCH` Feature that determines whether `ObjectWriter` should try to eagerly fetch necessary `JsonSerializer` when possible.
`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).
`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).
`FLUSH_AFTER_WRITE_VALUE` Feature that determines whether `JsonGenerator.flush()` is called after `writeValue()` method that takes JsonGenerator as an argument completes (i.e.
`INDENT_OUTPUT` Feature that allows enabling (or disabling) indentation for the underlying generator, using the default pretty printer (see `JsonGenerator.useDefaultPrettyPrinter()` for details).
`ORDER_MAP_ENTRIES_BY_KEYS` Feature that determines whether `Map` entries are first sorted by key before serialization or not: if enabled, additional sorting step is performed if necessary (not necessary for `SortedMap`s), if disabled, no additional sorting is needed.
`USE_EQUALITY_FOR_OBJECT_ID` Feature that determines whether Object Identity is compared using true JVM-level identity of Object (false); or, `equals()` method.
`WRAP_EXCEPTIONS` Feature that determines whether Jackson code should catch and wrap `Exception`s (but never `Error`s!) to add additional information about location (within input) of problem or not.
`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.
`WRITE_BIGDECIMAL_AS_PLAIN` Feature that determines whether `BigDecimal` entries are serialized using `BigDecimal.toPlainString()` to prevent values to be written using scientific notation.
`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).
`WRITE_DATE_KEYS_AS_TIMESTAMPS` Feature that determines whether `Date`s (and sub-types) used as `Map` keys are serialized as timestamps or not (if not, will be serialized as textual values).
`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.
`WRITE_DATES_AS_TIMESTAMPS` Feature that determines whether `Date` values (and Date-based things like `Calendar`s) are to be serialized as numeric timestamps (true; the default), or as something else (usually textual representation).
`WRITE_EMPTY_JSON_ARRAYS` Feature that determines whether Container properties (POJO properties with declared value of Collection or array; i.e.
`WRITE_ENUMS_USING_INDEX` Feature that determines whethere Java Enum values are serialized as numbers (true), or textual values (false).
`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.
`WRITE_NULL_MAP_VALUES` Feature that determines whether Map entries with null values are to be serialized (true) or not (false).
`WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED` Feature added for interoperability, to work with oddities of so-called "BadgerFish" convention.

### Method Summary

Methods
`boolean` `enabledByDefault()` Accessor for checking whether this feature is enabled by default.
`int` `getMask()` Returns bit mask for this feature instance
`static SerializationFeature` `valueOf(String name)` Returns the enum constant of this type with the specified name.
`static SerializationFeature[]` `values()` Returns an array containing the constants of this enum type, in the order they are declared.

### Methods inherited from class java.lang.Enum

`clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

### Enum Constant Detail

#### WRAP_ROOT_VALUE

    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.

#### INDENT_OUTPUT

    public static final SerializationFeature INDENT_OUTPUT

Feature that allows enabling (or disabling) indentation for the underlying generator, using the default pretty printer (see `JsonGenerator.useDefaultPrettyPrinter()` for details).

Note that this only affects cases where `JsonGenerator` is constructed implicitly by ObjectMapper: if explicit generator is passed, its configuration is not changed.

Also note that if you want to configure details of indentation, you need to directly configure the generator: there is a method to use any `PrettyPrinter` instance. This feature will only allow using the default implementation.

Feature is enabled by default.

#### FAIL_ON_EMPTY_BEANS

    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_REFERENCES

    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

#### WRAP_EXCEPTIONS

    public static final SerializationFeature WRAP_EXCEPTIONS

Feature that determines whether Jackson code should catch and wrap `Exception`s (but never `Error`s!) 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 `IOException`s 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.

#### CLOSE_CLOSEABLE

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

#### FLUSH_AFTER_WRITE_VALUE

    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.

#### WRITE_DATES_AS_TIMESTAMPS

    public static final SerializationFeature WRITE_DATES_AS_TIMESTAMPS

Feature that determines whether `Date` values (and Date-based things like `Calendar`s) are to be serialized as numeric timestamps (true; the default), or as something else (usually textual representation). If textual representation is used, the actual format is one returned by a call to `MapperConfig.getDateFormat()`: the default setting being `StdDateFormat`, which corresponds to format String of "yyyy-MM-dd'T'HH:mm:ss.SSSZ" (see `DateFormat` for details of format Strings).

Note: 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 `Map` keys are serialized as Strings or not is controlled using `WRITE_DATE_KEYS_AS_TIMESTAMPS`.

Feature is enabled by default.

#### WRITE_DATE_KEYS_AS_TIMESTAMPS

    public static final SerializationFeature WRITE_DATE_KEYS_AS_TIMESTAMPS

Feature that determines whether `Date`s (and sub-types) used as `Map` keys are serialized as timestamps 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_CHAR_ARRAYS_AS_JSON_ARRAYS

    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_ENUMS_USING_TO_STRING

    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_ENUMS_USING_INDEX

    public static final SerializationFeature WRITE_ENUMS_USING_INDEX

Feature that determines whethere 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.

Feature is disabled by default.

#### WRITE_NULL_MAP_VALUES

    public static final SerializationFeature WRITE_NULL_MAP_VALUES

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

For further details, check out [JACKSON-314]

Feature is enabled by default.

#### WRITE_EMPTY_JSON_ARRAYS

    public static final SerializationFeature WRITE_EMPTY_JSON_ARRAYS

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 `Map`s, or "Collection-like" types.

Feature is enabled by default.

#### WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED

    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 `Collection`s and arrays: if enabled, `Collection`s 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.

#### WRITE_BIGDECIMAL_AS_PLAIN

    public static final SerializationFeature WRITE_BIGDECIMAL_AS_PLAIN

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

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

Feature is disabled by default.

#### WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS

    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 `WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS`.

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

Since:
  2.2

#### ORDER_MAP_ENTRIES_BY_KEYS

    public static final SerializationFeature ORDER_MAP_ENTRIES_BY_KEYS

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

Feature is disabled by default.

#### EAGER_SERIALIZER_FETCH

    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

#### USE_EQUALITY_FOR_OBJECT_ID

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

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

Since:
  2.3

### Method Detail

#### values

    public static SerializationFeature[] values()

Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:

    for (SerializationFeature c : SerializationFeature.values())
        System.out.println(c);

Returns:
  an array containing the constants of this enum type, in the order they are declared

#### valueOf

    public static SerializationFeature valueOf(String name)

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
  `name` - the name of the enum constant to be returned.
Returns:
  the enum constant with the specified name
Throws:
  `IllegalArgumentException` - if this enum type has no constant with the specified name
  `NullPointerException` - if the argument is null

#### enabledByDefault

    public boolean enabledByDefault()

Description copied from interface: `ConfigFeature`
Accessor for checking whether this feature is enabled by default.

Specified by:
  `enabledByDefault` in interface `ConfigFeature`

#### getMask

    public int getMask()

Description copied from interface: `ConfigFeature`
Returns bit mask for this feature instance

Specified by:
  `getMask` in interface `ConfigFeature`