Enum Class SerializationFeature

java.lang.Object
java.lang.Enum<SerializationFeature>
tools.jackson.databind.SerializationFeature
All Implemented Interfaces:
Serializable, Comparable<SerializationFeature>, Constable, ConfigFeature

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.

  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Feature that determines whether close() method of serialized root level objects (ones for which ObjectMapper's (and ObjectWriter's) writeValue() (or equivalent) method is called) that implement AutoCloseable is called after serialization or not.
    Feature that determines whether ObjectWriter should try to eagerly fetch necessary ValueSerializer when possible.
    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).
    Feature that determines whether to intentionally fail when the mapper attempts to order map entries with incomparable keys by accessing the first key of the map.
    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 DatabindException is thrown (if true), or reference is normally processed (false).
    Feature that determines what happens when an object which normally has type information included by Jackson is used in conjunction with JsonUnwrapped.
    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.
    Feature that allows enabling (or disabling) indentation for the underlying generator, using the default pretty printer configured for ObjectMapper (and ObjectWriters created from mapper).
    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 SortedMaps), if disabled, no additional sorting is needed.
    Feature that determines whether Object Identity is compared using true JVM-level identity of Object (false); or, equals() method.
    Feature that determines whether Jackson code should catch and wrap Exceptions (but never Errors!)
    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 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).
    Deprecated.
    Since 2.8 there are better mechanism for specifying filtering; specifically using JsonInclude or configuration overrides.
    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).
    Feature added for interoperability, to work with oddities of so-called "BadgerFish" convention.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Accessor for checking whether this feature is enabled by default.
    boolean
    enabledIn(int flags)
    Convenience method for checking whether feature is enabled in given bitmask
    int
    Returns bit mask for this feature instance
    Returns the enum constant of this class with the specified name.
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • 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 configured for ObjectMapper (and ObjectWriters created from mapper).

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

      Feature is disabled 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 disabled by default as of Jackson 3.0 (in 2.x it was enabled).

    • 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 DatabindException is thrown (if true), or reference is normally processed (false).

      Feature is enabled by default.

    • WRAP_EXCEPTIONS

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

    • FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS

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

    • WRITE_SELF_REFERENCES_AS_NULL

      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 FAIL_ON_SELF_REFERENCES is enabled. this property is ignored.

      Feature is disabled 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 (and ObjectWriter's) writeValue() (or equivalent) method is called) that implement AutoCloseable is called after serialization or not. If enabled, close() will be called after serialization completes (whether successfully, 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.

      NOTE: in Jackson 2.x this used to only apply to Closeables, but now it also applies to AutoCloseables as well (as of Jackson 3.0).

      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_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_EMPTY_JSON_ARRAYS

      @Deprecated public static final SerializationFeature WRITE_EMPTY_JSON_ARRAYS
      Deprecated.
      Since 2.8 there are better mechanism for specifying filtering; specifically using 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 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.

    • 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 Collections and arrays: if enabled, 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.

    • 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 SortedMaps), if disabled, no additional sorting is needed.

      Feature is disabled by default.

    • FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY

      public static final SerializationFeature FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY
      Feature that determines whether to intentionally fail when the mapper attempts to order map entries with incomparable keys by accessing the first key of the map. So depending on the Map implementation, this may not be the same key every time.

      If enabled, will simply fail by throwing an exception. If disabled, will not throw an exception and instead simply return the original map.

      Note that this feature will apply only when configured to order map entries by keys, either through annotation or enabling ORDER_MAP_ENTRIES_BY_KEYS.

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

    • 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). 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(java.lang.Object) 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()

  • Method Details

    • values

      public static SerializationFeature[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SerializationFeature valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class 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
    • enabledIn

      public boolean enabledIn(int flags)
      Description copied from interface: ConfigFeature
      Convenience method for checking whether feature is enabled in given bitmask
      Specified by:
      enabledIn in interface ConfigFeature