Skip to content

Commit bd6546c

Browse files
committed
Fixes #5067; move date/time DeserializationFeatures into DateTimeFeature
1 parent 0b5aca5 commit bd6546c

20 files changed

+201
-191
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Versions: 3.x (for earlier see VERSION-2.x)
99

1010
#5065: Change default for `DateTimeFeature.ONE_BASED_MONTHS` to `true` in 3.0
1111
#5066: Move date/time `SerializationFeature`s into `DateTimeFeature` (3.0)
12+
#5067: Move date/time `DeserializationFeature`s into `DateTimeFeature` (3.0)
1213
- Branch rename "master" -> "3.x" [JSTEP-12]
1314

1415
3.0.0-rc3 (not yet released)

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

-37
Original file line numberDiff line numberDiff line change
@@ -449,43 +449,6 @@ public enum DeserializationFeature implements ConfigFeature
449449
*/
450450
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE(false),
451451

452-
/**
453-
* Feature that controls whether numeric timestamp values are expected
454-
* to be written using nanosecond timestamps (enabled) or not (disabled),
455-
* <b>if and only if</b> datatype supports such resolution.
456-
* Only newer datatypes (such as Java8 Date/Time) support such resolution --
457-
* older types (pre-Java8 <b>java.util.Date</b> etc) and Joda do not --
458-
* and this setting <b>has no effect</b> on such types.
459-
*<p>
460-
* If disabled, standard millisecond timestamps are assumed.
461-
* This is the counterpart to {@link DateTimeFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS}.
462-
*<p>
463-
* Feature is enabled by default, to support most accurate time values possible.
464-
*/
465-
READ_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
466-
467-
/**
468-
* Feature that specifies whether context provided {@link java.util.TimeZone}
469-
* ({@link DeserializationContext#getTimeZone()} should be used to adjust Date/Time
470-
* values on deserialization, even if value itself contains timezone information.
471-
* If enabled, contextual <code>TimeZone</code> will essentially override any other
472-
* TimeZone information; if disabled, it will only be used if value itself does not
473-
* contain any TimeZone information.
474-
*<p>
475-
* Note that exact behavior depends on date/time types in question; and specifically
476-
* JDK type of {@link java.util.Date} does NOT have in-built timezone information
477-
* so this setting has no effect.
478-
* Further, while {@link java.util.Calendar} does have this information basic
479-
* JDK {@link java.text.SimpleDateFormat} is unable to retain parsed zone information,
480-
* and as a result, {@link java.util.Calendar} will always get context timezone
481-
* adjustment regardless of this setting.
482-
*<p>
483-
*<p>
484-
* Taking above into account, this feature is supported only by extension modules for
485-
* Joda and Java 8 date/time datatypes.
486-
*/
487-
ADJUST_DATES_TO_CONTEXT_TIME_ZONE(true),
488-
489452
/*
490453
/**********************************************************************
491454
/* Other

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public enum MapperFeature
2828

2929
/**
3030
* Feature that determines whether otherwise regular "getter"
31-
* methods (but only ones that handle Collections and Maps,
32-
* not getters of other type)
33-
* can be used for purpose of getting a reference to a Collection
34-
* and Map to modify the property, without requiring a setter
35-
* method.
36-
* This is similar to how JAXB framework sets Collections and
37-
* Maps: no setter is involved, just getter.
31+
* methods (but only ones that handle {@link java.util.Collection}s
32+
* and {@link java.util.Map}s, not getters of other types)
33+
* can be used for purpose of getting a reference to
34+
* {@code Collection} / {@code Map} valued properties,
35+
* without requiring a setter method.
36+
* This is similar to how JAXB framework sets {@code Collection}s
37+
* and {@code Map}s: no setter is involved, just getter.
3838
*<p>
3939
* Note that such getters-as-setters methods have lower
4040
* precedence than setters, so they are only used if no

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

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package tools.jackson.databind.cfg;
22

3-
import tools.jackson.databind.DeserializationFeature;
3+
import tools.jackson.databind.DeserializationContext;
44

55
/**
66
* Configurable on/off features to configure Date/Time handling.
@@ -12,6 +12,30 @@
1212
*/
1313
public enum DateTimeFeature implements DatatypeFeature
1414
{
15+
/**
16+
* Feature that specifies whether context provided {@link java.util.TimeZone}
17+
* ({@link DeserializationContext#getTimeZone()} should be used to adjust Date/Time
18+
* values on deserialization, even if value itself contains timezone information.
19+
* If enabled, contextual <code>TimeZone</code> will essentially override any other
20+
* TimeZone information; if disabled, it will only be used if value itself does not
21+
* contain any TimeZone information.
22+
*<p>
23+
* Note that exact behavior depends on date/time types in question; and specifically
24+
* JDK type of {@link java.util.Date} does NOT have in-built timezone information
25+
* so this setting has no effect.
26+
* Further, while {@link java.util.Calendar} does have this information basic
27+
* JDK {@link java.text.SimpleDateFormat} is unable to retain parsed zone information,
28+
* and as a result, {@link java.util.Calendar} will always get context timezone
29+
* adjustment regardless of this setting.
30+
*<p>
31+
* Taking above into account, this feature is supported only by extension modules for
32+
* Joda and Java 8 date/time datatypes.
33+
*<p>
34+
* Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
35+
* in Jackson 2.x but was moved here in 3.0.
36+
*/
37+
ADJUST_DATES_TO_CONTEXT_TIME_ZONE(true),
38+
1539
/**
1640
* Feature that controls whether stringified numbers (Strings that without
1741
* quotes would be legal JSON Numbers) may be interpreted as
@@ -51,6 +75,25 @@ public enum DateTimeFeature implements DatatypeFeature
5175
*/
5276
ONE_BASED_MONTHS(true),
5377

78+
/**
79+
* Feature that controls whether numeric timestamp values are expected
80+
* to be written using nanosecond timestamps (enabled) or not (disabled),
81+
* <b>if and only if</b> datatype supports such resolution.
82+
* Only newer datatypes (such as Java8 Date/Time) support such resolution --
83+
* older types (pre-Java8 <b>java.util.Date</b> etc) and Joda do not --
84+
* and this setting <b>has no effect</b> on such types.
85+
*<p>
86+
* If disabled, standard millisecond timestamps are assumed.
87+
* This is the counterpart to {@link DateTimeFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS}.
88+
*<p>
89+
* Feature used to be one of {@link tools.jackson.databind.DeserializationFeature}s
90+
* in Jackson 2.x but was moved here in 3.0.
91+
*<p>
92+
* Feature is enabled by default, to support most accurate time values possible (where
93+
* available).
94+
*/
95+
READ_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
96+
5497
/**
5598
* Feature that determines whether the {@link java.util.TimeZone} of the
5699
* {@link tools.jackson.databind.DeserializationContext} is used
@@ -113,7 +156,7 @@ public enum DateTimeFeature implements DatatypeFeature
113156
* and this setting <b>has no effect</b> on such types.
114157
*<p>
115158
* If disabled, standard millisecond timestamps are assumed.
116-
* This is the counterpart to {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}.
159+
* This is the counterpart to {@link DateTimeFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}.
117160
*<p>
118161
* Feature used to be one of {@link tools.jackson.databind.SerializationFeature}s
119162
* in Jackson 2.x but was moved here in 3.0.

src/main/java/tools/jackson/databind/ext/javatime/JavaTimeInitializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* <p>
5454
* Granularity of timestamps is controlled through the companion features
5555
* {@link DateTimeFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} and
56-
* {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}. For serialization, timestamps are
56+
* {@link DateTimeFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS}. For serialization, timestamps are
5757
* written as fractional numbers (decimals), where the number is seconds and the decimal is fractional seconds, if
5858
* {@code WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} is enabled (it is by default), with resolution as fine as nanoseconds depending on the
5959
* underlying JDK implementation. If {@code WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} is disabled, timestamps are written as a whole number of

src/main/java/tools/jackson/databind/ext/javatime/deser/DurationDeserializer.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import tools.jackson.core.StreamReadCapability;
3030
import tools.jackson.core.io.NumberInput;
3131
import tools.jackson.databind.*;
32+
import tools.jackson.databind.cfg.DateTimeFeature;
3233
import tools.jackson.databind.ext.javatime.util.DecimalUtils;
3334
import tools.jackson.databind.ext.javatime.util.DurationUnitConverter;
3435

@@ -43,7 +44,7 @@ public class DurationDeserializer extends JSR310DeserializerBase<Duration>
4344
* When defined (not {@code null}) integer values will be converted into duration
4445
* unit configured for the converter.
4546
* Using this converter will typically override the value specified in
46-
* {@link DeserializationFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS} as it is
47+
* {@link DateTimeFeature#READ_DATE_TIMESTAMPS_AS_NANOSECONDS} as it is
4748
* considered that the unit set in {@link JsonFormat#pattern()} has precedence
4849
* since it is more specific.
4950
*<p>
@@ -209,6 +210,6 @@ protected Duration _fromTimestamp(DeserializationContext ctxt, long ts)
209210

210211
protected boolean shouldReadTimestampsAsNanoseconds(DeserializationContext context) {
211212
return (_readTimestampsAsNanosOverride != null) ? _readTimestampsAsNanosOverride :
212-
context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
213+
context.isEnabled(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
213214
}
214215
}

src/main/java/tools/jackson/databind/ext/javatime/deser/InstantDeserializer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ public T deserialize(JsonParser parser, DeserializationContext context)
287287

288288
protected boolean shouldAdjustToContextTimezone(DeserializationContext context) {
289289
return (_adjustToContextTZOverride != null) ? _adjustToContextTZOverride :
290-
context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
290+
context.isEnabled(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
291291
}
292292

293293
protected boolean shouldReadTimestampsAsNanoseconds(DeserializationContext context) {
294294
return (_readTimestampsAsNanosOverride != null) ? _readTimestampsAsNanosOverride :
295-
context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
295+
context.isEnabled(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
296296
}
297297

298298
// Helper method to find Strings of form "all digits" and "digits-comma-digits"

src/main/java/tools/jackson/databind/ext/javatime/deser/LocalDateTimeDeserializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public LocalDateTime deserialize(JsonParser parser, DeserializationContext conte
163163

164164
protected boolean shouldReadTimestampsAsNanoseconds(DeserializationContext context) {
165165
return (_readTimestampsAsNanosOverride != null) ? _readTimestampsAsNanosOverride :
166-
context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
166+
context.isEnabled(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
167167
}
168168

169169
protected LocalDateTime _fromString(JsonParser p, DeserializationContext ctxt,

src/main/java/tools/jackson/databind/ext/javatime/deser/LocalTimeDeserializer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import tools.jackson.databind.BeanProperty;
3030
import tools.jackson.databind.DeserializationContext;
3131
import tools.jackson.databind.DeserializationFeature;
32+
import tools.jackson.databind.cfg.DateTimeFeature;
3233

3334
/**
3435
* Deserializer for Java 8 temporal {@link LocalTime}s.
@@ -167,7 +168,7 @@ public LocalTime deserialize(JsonParser parser, DeserializationContext context)
167168

168169
protected boolean shouldReadTimestampsAsNanoseconds(DeserializationContext context) {
169170
return (_readTimestampsAsNanosOverride != null) ? _readTimestampsAsNanosOverride :
170-
context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
171+
context.isEnabled(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
171172
}
172173

173174
protected LocalTime _fromString(JsonParser p, DeserializationContext ctxt,

src/main/java/tools/jackson/databind/ext/javatime/deser/OffsetTimeDeserializer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.fasterxml.jackson.annotation.JsonFormat;
2626
import tools.jackson.core.*;
2727
import tools.jackson.databind.*;
28+
import tools.jackson.databind.cfg.DateTimeFeature;
2829

2930
/**
3031
* Deserializer for Java 8 temporal {@link OffsetTime}s.
@@ -172,7 +173,7 @@ public OffsetTime deserialize(JsonParser parser, DeserializationContext context)
172173

173174
protected boolean shouldReadTimestampsAsNanoseconds(DeserializationContext context) {
174175
return (_readTimestampsAsNanosOverride != null) ? _readTimestampsAsNanosOverride :
175-
context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
176+
context.isEnabled(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
176177
}
177178

178179
protected OffsetTime _fromString(JsonParser p, DeserializationContext ctxt,

src/test/java/tools/jackson/databind/deser/jdk/DateDeserializationTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.annotation.OptBoolean;
1313

1414
import tools.jackson.databind.*;
15+
import tools.jackson.databind.cfg.DateTimeFeature;
1516
import tools.jackson.databind.exc.InvalidFormatException;
1617
import tools.jackson.databind.exc.MismatchedInputException;
1718

@@ -642,7 +643,7 @@ public void testContextTimezone() throws Exception
642643
final String tzId = "PST";
643644

644645
// this is enabled by default:
645-
assertTrue(MAPPER.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
646+
assertTrue(MAPPER.isEnabled(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
646647
final ObjectReader r = MAPPER
647648
.readerFor(Calendar.class)
648649
.with(TimeZone.getTimeZone(tzId));
@@ -662,7 +663,7 @@ public void testContextTimezone() throws Exception
662663
assertEquals(11, cal.get(Calendar.HOUR_OF_DAY));
663664

664665
// but if disabled, should use what's been sent in:
665-
cal = r.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
666+
cal = r.without(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
666667
.readValue(q(inputStr));
667668

668669
// 23-Jun-2017, tatu: Actually turns out to be hard if not impossible to do ...

src/test/java/tools/jackson/databind/ext/javatime/TestFeatures.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21-
import tools.jackson.databind.DeserializationFeature;
2221
import tools.jackson.databind.cfg.DateTimeFeature;
2322

2423
import static org.junit.jupiter.api.Assertions.*;
@@ -35,14 +34,14 @@ public void testWriteDateTimestampsAsNanosecondsSettingEnabledByDefault()
3534
@Test
3635
public void testReadDateTimestampsAsNanosecondsSettingEnabledByDefault()
3736
{
38-
assertTrue(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault(),
37+
assertTrue(DateTimeFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS.enabledByDefault(),
3938
"Read date timestamps as nanoseconds setting should be enabled by default.");
4039
}
4140

4241
@Test
4342
public void testAdjustDatesToContextTimeZoneSettingEnabledByDefault()
4443
{
45-
assertTrue(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE.enabledByDefault(),
44+
assertTrue(DateTimeFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE.enabledByDefault(),
4645
"Adjust dates to context time zone setting should be enabled by default.");
4746
}
4847
}

0 commit comments

Comments
 (0)