|
1 | 1 | package tools.jackson.databind.cfg;
|
2 | 2 |
|
| 3 | +import tools.jackson.databind.DeserializationFeature; |
| 4 | + |
3 | 5 | /**
|
4 | 6 | * Configurable on/off features to configure Date/Time handling.
|
5 | 7 | * Mostly used to configure
|
@@ -58,8 +60,128 @@ public enum DateTimeFeature implements DatatypeFeature
|
58 | 60 | * Default setting is disabled, for backwards-compatibility with
|
59 | 61 | * Jackson 2.18.
|
60 | 62 | */
|
61 |
| - USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING(false) |
| 63 | + USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING(false), |
| 64 | + |
| 65 | + /** |
| 66 | + * Feature that determines whether Date (and date/time) values |
| 67 | + * (and Date-based things like {@link java.util.Calendar}s) are to be |
| 68 | + * serialized as numeric time stamps (true; the default), |
| 69 | + * or as something else (usually textual representation). |
| 70 | + * If textual representation is used, the actual format depends on configuration |
| 71 | + * settings including possible per-property use of {@code @JsonFormat} annotation, |
| 72 | + * globally configured {@link java.text.DateFormat}. |
| 73 | + *<p> |
| 74 | + * For "classic" JDK date types ({@link java.util.Date}, {@link java.util.Calendar}) |
| 75 | + * the default formatting is provided by {@link tools.jackson.databind.util.StdDateFormat}, |
| 76 | + * and corresponds to format String of "yyyy-MM-dd'T'HH:mm:ss.SSSX" |
| 77 | + * (see {@link java.text.DateFormat} for details of format Strings). |
| 78 | + * Whether this feature affects handling of other date-related |
| 79 | + * types depend on handlers of those types, although ideally they |
| 80 | + * should use this feature |
| 81 | + *<p> |
| 82 | + * Note: whether {@link java.util.Map} keys are serialized as Strings |
| 83 | + * or not is controlled using {@link #WRITE_DATE_KEYS_AS_TIMESTAMPS} instead of |
| 84 | + * this feature. |
| 85 | + *<p> |
| 86 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 87 | + * in Jackson 2.x but was moved here in 3.0. |
| 88 | + *<p> |
| 89 | + * Feature is disabled by default as of Jackson 3.0 (in 2.x it was enabled), |
| 90 | + * so that date/time are by default serialized as textual values NOT timestamps. |
| 91 | + */ |
| 92 | + WRITE_DATES_AS_TIMESTAMPS(false), |
62 | 93 |
|
| 94 | + /** |
| 95 | + * Feature that determines whether {@link java.util.Date}s |
| 96 | + * (and sub-types) used as {@link java.util.Map} keys are serialized |
| 97 | + * as time stamps or not (if not, will be serialized as textual values). |
| 98 | + *<p> |
| 99 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 100 | + * in Jackson 2.x but was moved here in 3.0. |
| 101 | + *<p> |
| 102 | + * Feature is disabled by default, meaning that Date-valued Map keys are serialized |
| 103 | + * as textual (ISO-8601) values. |
| 104 | + */ |
| 105 | + WRITE_DATE_KEYS_AS_TIMESTAMPS(false), |
| 106 | + |
| 107 | + /** |
| 108 | + * Feature that controls whether numeric timestamp values are |
| 109 | + * to be written using nanosecond timestamps (enabled) or not (disabled); |
| 110 | + * <b>if and only if</b> datatype supports such resolution. |
| 111 | + * Only newer datatypes (such as Java8 Date/Time) support such resolution -- |
| 112 | + * older types (pre-Java8 <b>java.util.Date</b> etc) and Joda do not -- |
| 113 | + * and this setting <b>has no effect</b> on such types. |
| 114 | + *<p> |
| 115 | + * If disabled, standard millisecond timestamps are assumed. |
| 116 | + * This is the counterpart to {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}. |
| 117 | + *<p> |
| 118 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 119 | + * in Jackson 2.x but was moved here in 3.0. |
| 120 | + *<p> |
| 121 | + * Feature is enabled by default, to support most accurate time values possible. |
| 122 | + */ |
| 123 | + WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS(true), |
| 124 | + |
| 125 | + /** |
| 126 | + * Feature that determines whether timezone/offset included in zoned date/time |
| 127 | + * values (note: does NOT {@link java.util.Date} will be overridden if there |
| 128 | + * is an explicitly set context time zone. |
| 129 | + * If disabled, timezone/offset value is used-is; if enabled, context time zone |
| 130 | + * is used instead. |
| 131 | + *<p> |
| 132 | + * Note that this setting only affects "Zoned" date/time values of |
| 133 | + * {@code Java 8 date/time} types -- it will have no effect on old |
| 134 | + * {@link java.util} value handling (of which {@link java.util.Date} has no timezone |
| 135 | + * information and must use contextual timezone, implicit or explicit; and |
| 136 | + * {@link java.util.Calendar} which will always use timezone Calendar value has). |
| 137 | + * Setting is also ignored by Joda date/time values. |
| 138 | + *<p> |
| 139 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 140 | + * in Jackson 2.x but was moved here in 3.0. |
| 141 | + *<p> |
| 142 | + * Feature is enabled by default for backwards-compatibility purposes |
| 143 | + * (from Jackson 2.x) |
| 144 | + */ |
| 145 | + WRITE_DATES_WITH_CONTEXT_TIME_ZONE(true), |
| 146 | + |
| 147 | + /** |
| 148 | + * Feature that determines whether date/date-time values should be serialized |
| 149 | + * so that they include timezone id, in cases where type itself contains |
| 150 | + * timezone information. Including this information may lead to compatibility |
| 151 | + * issues because ISO-8601 specification does not define formats that include |
| 152 | + * such information. |
| 153 | + *<p> |
| 154 | + * If enabled, Timezone id should be included using format specified |
| 155 | + * with Java 8 <code>DateTimeFormatter#ISO_ZONED_DATE_TIME</code> definition |
| 156 | + * (for example, '2011-12-03T10:15:30+01:00[Europe/Paris]'). |
| 157 | + *<p> |
| 158 | + * Note: setting has no relevance if date/time values are serialized as timestamps. |
| 159 | + *<p> |
| 160 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 161 | + * in Jackson 2.x but was moved here in 3.0. |
| 162 | + *<p> |
| 163 | + * Feature is disabled by default, so that zone id is NOT included; rather, timezone |
| 164 | + * offset is used for ISO-8601 compatibility (if any timezone information is |
| 165 | + * included in value). |
| 166 | + */ |
| 167 | + WRITE_DATES_WITH_ZONE_ID(false), |
| 168 | + |
| 169 | + /** |
| 170 | + * Feature that determines whether time values that represents time periods |
| 171 | + * (durations, periods, ranges) are to be serialized by default using |
| 172 | + * a numeric (true) or textual (false) representations. Note that numeric |
| 173 | + * representation may mean either simple number, or an array of numbers, |
| 174 | + * depending on type. |
| 175 | + *<p> |
| 176 | + * Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s |
| 177 | + * in Jackson 2.x but was moved here in 3.0. |
| 178 | + *<p> |
| 179 | + * Feature is disabled by default as of Jackson 3.0 (in 2.x it was enabled), |
| 180 | + * so that period/duration are by default serialized as textual values, |
| 181 | + * NOT timestamps. |
| 182 | + */ |
| 183 | + WRITE_DURATIONS_AS_TIMESTAMPS(false), |
| 184 | + |
63 | 185 | ;
|
64 | 186 |
|
65 | 187 | private final static int FEATURE_INDEX = DatatypeFeatures.FEATURE_INDEX_DATETIME;
|
|
0 commit comments