Enum Class DateTimeFeature

java.lang.Object
java.lang.Enum<DateTimeFeature>
tools.jackson.databind.cfg.DateTimeFeature
All Implemented Interfaces:
Serializable, Comparable<DateTimeFeature>, Constable, JacksonFeature, DatatypeFeature

public enum DateTimeFeature extends Enum<DateTimeFeature> implements DatatypeFeature
Configurable on/off features to configure Date/Time handling. Mostly used to configure Java 8 Time (java.time) type handling (see JavaTimeInitializer) but also to "legacy" (Date, Calendar) and Joda Date/Time.
  • Enum Constant Details

    • ADJUST_DATES_TO_CONTEXT_TIME_ZONE

      public static final DateTimeFeature ADJUST_DATES_TO_CONTEXT_TIME_ZONE
      Feature that specifies whether context provided TimeZone (DeserializationContext.getTimeZone() should be used to adjust Date/Time values on deserialization, even if value itself contains timezone information. If enabled, contextual TimeZone will essentially override any other TimeZone information; if disabled, it will only be used if value itself does not contain any TimeZone information.

      Note that exact behavior depends on date/time types in question; and specifically JDK type of Date does NOT have in-built timezone information so this setting has no effect. Further, while Calendar does have this information basic JDK SimpleDateFormat is unable to retain parsed zone information, and as a result, Calendar will always get context timezone adjustment regardless of this setting.

      Taking above into account, this feature is supported only by extension modules for Joda and Java 8 date/time datatypes.

      Feature used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

    • ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS

      public static final DateTimeFeature ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS
      Feature that controls whether stringified numbers (Strings that without quotes would be legal JSON Numbers) may be interpreted as timestamps (enabled) or not (disabled), in case where there is an explicitly defined pattern (DateTimeFormatter, usually by using @JsonFormat annotation) for value.

      Note that when the default pattern is used (no custom pattern defined), stringified numbers are always accepted as timestamps regardless of this feature.

    • NORMALIZE_DESERIALIZED_ZONE_ID

      public static final DateTimeFeature NORMALIZE_DESERIALIZED_ZONE_ID
      Feature that determines whether ZoneId is normalized (via call to java.time.ZoneId#normalized()) when deserializing types like ZonedDateTime.

      Default setting is enabled, for backwards-compatibility with Jackson 2.15.

    • ONE_BASED_MONTHS

      public static final DateTimeFeature ONE_BASED_MONTHS
      Feature that determines whether Month is serialized as and deserialized expected a zero- (false) or one-based index (true). For example, Month.JANUARY would be serialized as 1 when enabled but as 0 when disabled. Conversely JSON Number 1 would be deserialized as Month.JANUARY when enabled, but as Month.FEBRUARY when disabled.

      Default setting is true, meaning that Month is serialized using one-based index and deserialized expecting one-based index.

      NOTE: default setting changed between Jackson 2.x (was false) and Jackson 3.0 (changed to true).

    • READ_DATE_TIMESTAMPS_AS_NANOSECONDS

      public static final DateTimeFeature READ_DATE_TIMESTAMPS_AS_NANOSECONDS
      Feature that controls whether numeric timestamp values are expected 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 used to be one of DeserializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is enabled by default, to support most accurate time values possible (where available).

    • USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING

      public static final DateTimeFeature USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING
      Feature that determines whether the TimeZone of the DeserializationContext is used when leniently deserializing LocalDate or LocalDateTime from the UTC/ISO instant format.

      Default setting is disabled, for backwards-compatibility with Jackson 2.18.

    • WRITE_DATES_AS_TIMESTAMPS

      public static final DateTimeFeature WRITE_DATES_AS_TIMESTAMPS
      Feature that determines whether Date (and date/time) values (and Date-based things like 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 DateFormat.

      For "classic" JDK date types (Date, Calendar) the default formatting is provided by StdDateFormat, and corresponds to format String of "yyyy-MM-dd'T'HH:mm:ss.SSSX" (see 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 Map keys are serialized as Strings or not is controlled using WRITE_DATE_KEYS_AS_TIMESTAMPS instead of this feature.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default as of Jackson 3.0 (in 2.x it was enabled), so that date/time are by default serialized as textual values NOT timestamps.

    • WRITE_DATE_KEYS_AS_TIMESTAMPS

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

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default, meaning that Date-valued Map keys are serialized as textual (ISO-8601) values.

    • WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS

      public static final DateTimeFeature 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 READ_DATE_TIMESTAMPS_AS_NANOSECONDS.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

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

    • WRITE_DATES_WITH_CONTEXT_TIME_ZONE

      public static final DateTimeFeature WRITE_DATES_WITH_CONTEXT_TIME_ZONE
      Feature that determines whether timezone/offset included in zoned date/time values (note: does NOT 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 Date has no timezone information and must use contextual timezone, implicit or explicit; and Calendar which will always use timezone Calendar value has). Setting is also ignored by Joda date/time values.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is enabled by default for backwards-compatibility purposes (from Jackson 2.x)

    • WRITE_DATES_WITH_ZONE_ID

      public static final DateTimeFeature 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 used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

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

    • WRITE_DURATIONS_AS_TIMESTAMPS

      public static final DateTimeFeature 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.

      Feature used to be one of SerializationFeatures in Jackson 2.x but was moved here in 3.0.

      Feature is disabled by default as of Jackson 3.0 (in 2.x it was enabled), so that period/duration are by default serialized as textual values, NOT timestamps.

  • Method Details

    • values

      public static DateTimeFeature[] 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 DateTimeFeature 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()
      Specified by:
      enabledByDefault in interface JacksonFeature
    • enabledIn

      public boolean enabledIn(int flags)
      Specified by:
      enabledIn in interface JacksonFeature
    • getMask

      public int getMask()
      Specified by:
      getMask in interface JacksonFeature
    • featureIndex

      public int featureIndex()
      Description copied from interface: DatatypeFeature
      Internal index used for efficient storage and index; no user serviceable contents inside!
      Specified by:
      featureIndex in interface DatatypeFeature