Skip to content

Commit 766923c

Browse files
authored
Move jackson-datatype-jsr310 into jackson-databind (#5032)
1 parent cd955e6 commit 766923c

File tree

135 files changed

+17033
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+17033
-176
lines changed

src/main/java/module-info.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
exports tools.jackson.databind.deser.std;
3636
exports tools.jackson.databind.exc;
3737
exports tools.jackson.databind.ext;
38+
exports tools.jackson.databind.ext.javatime;
39+
exports tools.jackson.databind.ext.javatime.deser;
40+
exports tools.jackson.databind.ext.javatime.deser.key;
41+
exports tools.jackson.databind.ext.javatime.ser;
42+
exports tools.jackson.databind.ext.javatime.ser.key;
3843
exports tools.jackson.databind.ext.jdk8;
3944
// Needed by Ion module for SqlDate deserializer:
4045
exports tools.jackson.databind.ext.sql;

src/main/java/tools/jackson/databind/JacksonModule.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import java.util.function.UnaryOperator;
66

77
import tools.jackson.core.*;
8-
import tools.jackson.databind.cfg.MapperBuilder;
9-
import tools.jackson.databind.cfg.MutableConfigOverride;
8+
import tools.jackson.databind.cfg.*;
109
import tools.jackson.databind.deser.*;
1110
import tools.jackson.databind.jsontype.NamedType;
1211
import tools.jackson.databind.ser.Serializers;
@@ -146,6 +145,9 @@ public static interface SetupContext
146145
public boolean isEnabled(TokenStreamFactory.Feature f);
147146
public boolean isEnabled(StreamReadFeature f);
148147
public boolean isEnabled(StreamWriteFeature f);
148+
public boolean isEnabled(DatatypeFeature f);
149+
150+
public DatatypeFeatures datatypeFeatures();
149151

150152
/*
151153
/******************************************************************

src/main/java/tools/jackson/databind/SerializationFeature.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ public enum SerializationFeature implements ConfigFeature
210210
*/
211211
WRITE_DATE_KEYS_AS_TIMESTAMPS(false),
212212

213+
/**
214+
* Feature that controls whether numeric timestamp values are
215+
* to be written using nanosecond timestamps (enabled) or not (disabled);
216+
* <b>if and only if</b> datatype supports such resolution.
217+
* Only newer datatypes (such as Java8 Date/Time) support such resolution --
218+
* older types (pre-Java8 <b>java.util.Date</b> etc) and Joda do not --
219+
* and this setting <b>has no effect</b> on such types.
220+
*<p>
221+
* If disabled, standard millisecond timestamps are assumed.
222+
* This is the counterpart to {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}.
223+
*<p>
224+
* Feature is enabled by default, to support most accurate time values possible.
225+
*/
226+
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
227+
213228
/**
214229
* Feature that determines whether date/date-time values should be serialized
215230
* so that they include timezone id, in cases where type itself contains
@@ -360,21 +375,6 @@ public enum SerializationFeature implements ConfigFeature
360375
*/
361376
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED(false),
362377

363-
/**
364-
* Feature that controls whether numeric timestamp values are
365-
* to be written using nanosecond timestamps (enabled) or not (disabled);
366-
* <b>if and only if</b> datatype supports such resolution.
367-
* Only newer datatypes (such as Java8 Date/Time) support such resolution --
368-
* older types (pre-Java8 <b>java.util.Date</b> etc) and Joda do not --
369-
* and this setting <b>has no effect</b> on such types.
370-
*<p>
371-
* If disabled, standard millisecond timestamps are assumed.
372-
* This is the counterpart to {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}.
373-
*<p>
374-
* Feature is enabled by default, to support most accurate time values possible.
375-
*/
376-
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
377-
378378
/**
379379
* Feature that determines whether {@link java.util.Map} entries are first
380380
* sorted by key before serialization or not: if enabled, additional sorting

src/main/java/tools/jackson/databind/cfg/DatatypeFeatures.java

+60-19
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,38 @@ public class DatatypeFeatures
1414

1515
protected final static int FEATURE_INDEX_ENUM = 0;
1616
protected final static int FEATURE_INDEX_JSON_NODE = 1;
17+
protected final static int FEATURE_INDEX_DATETIME = 2;
1718

18-
private final int _enabledFor1, _enabledFor2;
19+
private final int _enabledFor1, _enabledFor2, _enabledFor3;
1920

20-
private final int _explicitFor1, _explicitFor2;
21+
private final int _explicitFor1, _explicitFor2, _explicitFor3;
2122

2223
protected DatatypeFeatures(int enabledFor1, int explicitFor1,
23-
int enabledFor2, int explicitFor2) {
24+
int enabledFor2, int explicitFor2,
25+
int enabledFor3, int explicitFor3) {
2426
_enabledFor1 = enabledFor1;
2527
_explicitFor1 = explicitFor1;
2628
_enabledFor2 = enabledFor2;
2729
_explicitFor2 = explicitFor2;
30+
_enabledFor3 = enabledFor3;
31+
_explicitFor3 = explicitFor3;
2832
}
2933

3034
public static DatatypeFeatures defaultFeatures() {
3135
return DefaultHolder.getDefault();
3236
}
3337

3438
private DatatypeFeatures _with(int enabledFor1, int explicitFor1,
35-
int enabledFor2, int explicitFor2) {
39+
int enabledFor2, int explicitFor2,
40+
int enabledFor3, int explicitFor3) {
3641
if ((_enabledFor1 == enabledFor1) && (_explicitFor1 == explicitFor1)
37-
&& (_enabledFor2 == enabledFor2) && (_explicitFor2 == explicitFor2)) {
42+
&& (_enabledFor2 == enabledFor2) && (_explicitFor2 == explicitFor2)
43+
&& (_enabledFor3 == enabledFor3) && (_explicitFor3 == explicitFor3)) {
3844
return this;
3945
}
4046
return new DatatypeFeatures(enabledFor1, explicitFor1,
41-
enabledFor2, explicitFor2);
47+
enabledFor2, explicitFor2,
48+
enabledFor3, explicitFor3);
4249
}
4350

4451
/*
@@ -61,10 +68,16 @@ public DatatypeFeatures with(DatatypeFeature f) {
6168
switch (f.featureIndex()) {
6269
case 0:
6370
return _with(_enabledFor1 | mask, _explicitFor1 | mask,
64-
_enabledFor2, _explicitFor2);
71+
_enabledFor2, _explicitFor2,
72+
_enabledFor3, _explicitFor3);
6573
case 1:
6674
return _with(_enabledFor1, _explicitFor1,
67-
_enabledFor2 | mask, _explicitFor2 | mask);
75+
_enabledFor2 | mask, _explicitFor2 | mask,
76+
_enabledFor3, _explicitFor3);
77+
case 2:
78+
return _with(_enabledFor1, _explicitFor1,
79+
_enabledFor2, _explicitFor2,
80+
_enabledFor3 | mask, _explicitFor3 | mask);
6881
default:
6982
VersionUtil.throwInternal();
7083
return this;
@@ -88,10 +101,16 @@ public DatatypeFeatures withFeatures(DatatypeFeature... features) {
88101
switch (features[0].featureIndex()) {
89102
case 0:
90103
return _with(_enabledFor1 | mask, _explicitFor1 | mask,
91-
_enabledFor2, _explicitFor2);
104+
_enabledFor2, _explicitFor2,
105+
_enabledFor3, _explicitFor3);
92106
case 1:
93107
return _with(_enabledFor1, _explicitFor1,
94-
_enabledFor2 | mask, _explicitFor2 | mask);
108+
_enabledFor2 | mask, _explicitFor2 | mask,
109+
_enabledFor3, _explicitFor3);
110+
case 2:
111+
return _with(_enabledFor1, _explicitFor1,
112+
_enabledFor2, _explicitFor2,
113+
_enabledFor3 | mask, _explicitFor3 | mask);
95114
default:
96115
VersionUtil.throwInternal();
97116
return this;
@@ -112,10 +131,16 @@ public DatatypeFeatures without(DatatypeFeature f) {
112131
switch (f.featureIndex()) {
113132
case 0:
114133
return _with(_enabledFor1 & ~mask, _explicitFor1 | mask,
115-
_enabledFor2, _explicitFor2);
134+
_enabledFor2, _explicitFor2,
135+
_enabledFor3, _explicitFor3);
116136
case 1:
117137
return _with(_enabledFor1, _explicitFor1,
118-
_enabledFor2 & ~mask, _explicitFor2 | mask);
138+
_enabledFor2 & ~mask, _explicitFor2 | mask,
139+
_enabledFor3, _explicitFor3);
140+
case 2:
141+
return _with(_enabledFor1, _explicitFor1,
142+
_enabledFor2, _explicitFor2,
143+
_enabledFor3 & ~mask, _explicitFor3 | mask);
119144
default:
120145
VersionUtil.throwInternal();
121146
return this;
@@ -139,10 +164,16 @@ public DatatypeFeatures withoutFeatures(DatatypeFeature... features) {
139164
switch (features[0].featureIndex()) {
140165
case 0:
141166
return _with(_enabledFor1 & ~mask, _explicitFor1 | mask,
142-
_enabledFor2, _explicitFor2);
167+
_enabledFor2, _explicitFor2,
168+
_enabledFor3, _explicitFor3);
143169
case 1:
144170
return _with(_enabledFor1, _explicitFor1,
145-
_enabledFor2 & ~mask, _explicitFor2 | mask);
171+
_enabledFor2 & ~mask, _explicitFor2 | mask,
172+
_enabledFor3, _explicitFor3);
173+
case 2:
174+
return _with(_enabledFor1, _explicitFor1,
175+
_enabledFor2, _explicitFor2,
176+
_enabledFor3 & ~mask, _explicitFor3 | mask);
146177
default:
147178
VersionUtil.throwInternal();
148179
return this;
@@ -179,6 +210,8 @@ public boolean isEnabled(DatatypeFeature f) {
179210
return f.enabledIn(_enabledFor1);
180211
case 1:
181212
return f.enabledIn(_enabledFor2);
213+
case 2:
214+
return f.enabledIn(_enabledFor3);
182215
default:
183216
VersionUtil.throwInternal();
184217
return false;
@@ -200,6 +233,8 @@ public boolean isExplicitlySet(DatatypeFeature f) {
200233
return f.enabledIn(_explicitFor1);
201234
case 1:
202235
return f.enabledIn(_explicitFor2);
236+
case 2:
237+
return f.enabledIn(_explicitFor3);
203238
default:
204239
VersionUtil.throwInternal();
205240
return false;
@@ -215,15 +250,15 @@ public boolean isExplicitlySet(DatatypeFeature f) {
215250
* @param f Feature to check
216251
*
217252
* @return Whether given feature has been explicitly enabled
218-
*
219-
* @since 2.15
220253
*/
221254
public boolean isExplicitlyEnabled(DatatypeFeature f) {
222255
switch (f.featureIndex()) {
223256
case 0:
224257
return f.enabledIn(_explicitFor1 & _enabledFor1);
225258
case 1:
226259
return f.enabledIn(_explicitFor2 & _enabledFor2);
260+
case 2:
261+
return f.enabledIn(_explicitFor3 & _enabledFor3);
227262
default:
228263
VersionUtil.throwInternal();
229264
return false;
@@ -239,15 +274,15 @@ public boolean isExplicitlyEnabled(DatatypeFeature f) {
239274
* @param f Feature to check
240275
*
241276
* @return Whether given feature has been explicitly disabled
242-
*
243-
* @since 2.15
244277
*/
245278
public boolean isExplicitlyDisabled(DatatypeFeature f) {
246279
switch (f.featureIndex()) {
247280
case 0:
248281
return f.enabledIn(_explicitFor1 & ~_enabledFor1);
249282
case 1:
250283
return f.enabledIn(_explicitFor2 & ~_enabledFor2);
284+
case 2:
285+
return f.enabledIn(_explicitFor3 & ~_enabledFor3);
251286
default:
252287
VersionUtil.throwInternal();
253288
return false;
@@ -276,6 +311,11 @@ public Boolean getExplicitState(DatatypeFeature f) {
276311
return f.enabledIn(_enabledFor2);
277312
}
278313
return null;
314+
case 2:
315+
if (f.enabledIn(_explicitFor3)) {
316+
return f.enabledIn(_enabledFor3);
317+
}
318+
return null;
279319
default:
280320
VersionUtil.throwInternal();
281321
return null;
@@ -298,7 +338,8 @@ private static class DefaultHolder
298338
static {
299339
DEFAULT_FEATURES = new DatatypeFeatures(
300340
collectDefaults(EnumFeature.values()), 0,
301-
collectDefaults(JsonNodeFeature.values()), 0
341+
collectDefaults(JsonNodeFeature.values()), 0,
342+
collectDefaults(DateTimeFeature.values()), 0
302343
);
303344
}
304345

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package tools.jackson.databind.cfg;
2+
3+
/**
4+
* Configurable on/off features to configure Date/Time handling.
5+
* Mostly used to configure
6+
* Java 8 Time ({@code java.time}) type handling (see
7+
* {@link tools.jackson.databind.ext.javatime.JavaTimeInitializer})
8+
* but also to "legacy" ({@link java.util.Date}, {@link java.util.Calendar})
9+
* and Joda Date/Time.
10+
*/
11+
public enum DateTimeFeature implements DatatypeFeature
12+
{
13+
/**
14+
* Feature that determines whether {@link java.time.ZoneId} is normalized
15+
* (via call to {@code java.time.ZoneId#normalized()}) when deserializing
16+
* types like {@link java.time.ZonedDateTime}.
17+
*<p>
18+
* Default setting is enabled, for backwards-compatibility with
19+
* Jackson 2.15.
20+
*/
21+
NORMALIZE_DESERIALIZED_ZONE_ID(true),
22+
23+
/**
24+
* Feature that determines whether the {@link java.util.TimeZone} of the
25+
* {@link tools.jackson.databind.DeserializationContext} is used
26+
* when leniently deserializing {@link java.time.LocalDate} or
27+
* {@link java.time.LocalDateTime} from the UTC/ISO instant format.
28+
* <p>
29+
* Default setting is disabled, for backwards-compatibility with
30+
* Jackson 2.18.
31+
*
32+
* @since 2.19
33+
*/
34+
USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING(false),
35+
36+
/**
37+
* Feature that controls whether stringified numbers (Strings that without
38+
* quotes would be legal JSON Numbers) may be interpreted as
39+
* timestamps (enabled) or not (disabled), in case where there is an
40+
* explicitly defined pattern ({@code DateTimeFormatter}, usually by
41+
* using {@code @JsonFormat} annotation) for value.
42+
* <p>
43+
* Note that when the default pattern is used (no custom pattern defined),
44+
* stringified numbers are always accepted as timestamps regardless of
45+
* this feature.
46+
*/
47+
ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS(false),
48+
49+
/**
50+
* Feature that determines whether {@link java.time.Month} is serialized
51+
* and deserialized as using a zero-based index (FALSE) or a one-based index (TRUE).
52+
* For example, "1" would be serialized/deserialized as Month.JANUARY if TRUE and Month.FEBRUARY if FALSE.
53+
*<p>
54+
* Default setting is false, meaning that Month is serialized/deserialized as a zero-based index.
55+
*/
56+
ONE_BASED_MONTHS(false)
57+
;
58+
59+
private final static int FEATURE_INDEX = DatatypeFeatures.FEATURE_INDEX_DATETIME;
60+
61+
/**
62+
* Whether feature is enabled or disabled by default.
63+
*/
64+
private final boolean _enabledByDefault;
65+
66+
private final int _mask;
67+
68+
private DateTimeFeature(boolean enabledByDefault) {
69+
_enabledByDefault = enabledByDefault;
70+
_mask = (1 << ordinal());
71+
}
72+
73+
@Override
74+
public boolean enabledByDefault() { return _enabledByDefault; }
75+
@Override
76+
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }
77+
@Override
78+
public int getMask() { return _mask; }
79+
80+
@Override
81+
public int featureIndex() {
82+
return FEATURE_INDEX;
83+
}
84+
}

src/main/java/tools/jackson/databind/cfg/MapperBuilder.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import tools.jackson.core.util.Snapshottable;
1717
import tools.jackson.databind.*;
1818
import tools.jackson.databind.deser.*;
19+
import tools.jackson.databind.ext.javatime.JavaTimeInitializer;
1920
import tools.jackson.databind.introspect.*;
2021
import tools.jackson.databind.jsontype.*;
2122
import tools.jackson.databind.jsontype.impl.DefaultTypeResolverBuilder;
@@ -419,8 +420,9 @@ public MapperBuilderState saveStateApplyModules()
419420
{
420421
if (_savedState == null) {
421422
_savedState = _saveState();
423+
ModuleContextBase ctxt = _constructModuleContext();
424+
JavaTimeInitializer.getInstance().setupModule(ctxt);
422425
if (_modules != null) {
423-
ModuleContextBase ctxt = _constructModuleContext();
424426
_modules.values().forEach(m -> m.setupModule(ctxt));
425427
// and since context may buffer some changes, ensure those are flushed:
426428
ctxt.applyChanges(this);
@@ -485,7 +487,6 @@ public boolean isEnabled(SerializationFeature f) {
485487
public boolean isEnabled(DatatypeFeature f) {
486488
return _datatypeFeatures.isEnabled(f);
487489
}
488-
489490
public boolean isEnabled(StreamReadFeature f) {
490491
return f.enabledIn(_streamReadFeatures);
491492
}

0 commit comments

Comments
 (0)