Skip to content

Commit d95b35f

Browse files
committed
Merge branch '2.10'
2 parents fb16f4d + 7fb7e4d commit d95b35f

File tree

7 files changed

+149
-93
lines changed

7 files changed

+149
-93
lines changed

datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/JavaTimeModule.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@
8888
* </pre>
8989
*<p>
9090
* Most {@code java.time} types are serialized as numbers (integers or decimals as appropriate) if the
91-
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} feature is enabled, and otherwise are serialized in
92-
* standard <a href="http://en.wikipedia.org/wiki/ISO_8601" target="_blank">ISO-8601</a> string representation. ISO-8601 specifies formats
93-
* for representing offset dates and times, zoned dates and times, local dates and times, periods, durations, zones, and more. All
94-
* {@code java.time} types have built-in translation to and from ISO-8601 formats.
91+
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} feature is enabled
92+
* (or, for {@link Duration}, {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DURATIONS_AS_TIMESTAMPS}),
93+
* and otherwise are serialized in standard
94+
* <a href="http://en.wikipedia.org/wiki/ISO_8601" target="_blank">ISO-8601</a> string representation.
95+
* ISO-8601 specifies formats for representing offset dates and times, zoned dates and times,
96+
* local dates and times, periods, durations, zones, and more. All {@code java.time} types
97+
* have built-in translation to and from ISO-8601 formats.
9598
* <p>
9699
* Granularity of timestamps is controlled through the companion features
97100
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} and
@@ -149,7 +152,6 @@ public JavaTimeModule()
149152
addDeserializer(ZoneId.class, JSR310StringParsableDeserializer.ZONE_ID);
150153
addDeserializer(ZoneOffset.class, JSR310StringParsableDeserializer.ZONE_OFFSET);
151154

152-
153155
// then serializers:
154156
addSerializer(Duration.class, DurationSerializer.INSTANCE);
155157
addSerializer(Instant.class, InstantSerializer.INSTANCE);

datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/DurationSerializer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import com.fasterxml.jackson.core.JsonGenerator;
2121
import com.fasterxml.jackson.core.JsonParser;
2222
import com.fasterxml.jackson.core.JsonToken;
23+
2324
import com.fasterxml.jackson.databind.JavaType;
2425
import com.fasterxml.jackson.databind.JsonMappingException;
26+
import com.fasterxml.jackson.databind.SerializationFeature;
2527
import com.fasterxml.jackson.databind.SerializerProvider;
2628
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
2729
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor;
@@ -34,6 +36,11 @@
3436

3537
/**
3638
* Serializer for Java 8 temporal {@link Duration}s.
39+
*<p>
40+
* NOTE: since 2.10, {@link SerializationFeature#WRITE_DURATIONS_AS_TIMESTAMPS}
41+
* determines global default used for determining if serialization should use
42+
* numeric (timestamps) or textual representation. Before this,
43+
* {@link SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} was used.
3744
*
3845
* @author Nick Williams
3946
* @since 2.2
@@ -63,7 +70,13 @@ protected DurationSerializer withFormat(DateTimeFormatter dtf,
6370
Boolean useTimestamp, JsonFormat.Shape shape) {
6471
return new DurationSerializer(this, dtf, useTimestamp);
6572
}
66-
73+
74+
// @since 2.10
75+
@Override
76+
protected SerializationFeature getTimestampsFeature() {
77+
return SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS;
78+
}
79+
6780
@Override
6881
public void serialize(Duration duration, JsonGenerator generator,
6982
SerializerProvider provider) throws IOException

datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/ser/JSR310FormattedSerializerBase.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaTyp
171171
}
172172
}
173173

174+
/**
175+
* Overridable method that determines {@link SerializationFeature} that is used as
176+
* the global default in determining if date/time value serialized should use numeric
177+
* format ("timestamp") or not.
178+
*<p>
179+
* Note that this feature is just the baseline setting and may be overridden on per-type
180+
* or per-property basis.
181+
*
182+
* @since 2.10
183+
*/
184+
protected SerializationFeature getTimestampsFeature() {
185+
return SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
186+
}
187+
174188
protected boolean useTimestamp(SerializerProvider provider) {
175189
if (_useTimestamp != null) {
176190
return _useTimestamp.booleanValue();
@@ -184,7 +198,7 @@ protected boolean useTimestamp(SerializerProvider provider) {
184198
}
185199
}
186200
// assume that explicit formatter definition implies use of textual format
187-
return _formatter == null && provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
201+
return (_formatter == null) && provider.isEnabled(getTimestampsFeature());
188202
}
189203

190204
protected boolean _useTimestampExplicitOnly(SerializerProvider provider) {

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/TestDurationSerialization.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testSerializationAsTimestampNanoseconds01() throws Exception
2727
{
2828
Duration duration = Duration.ofSeconds(60L, 0);
2929
String value = WRITER
30-
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
30+
.with(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
3131
.with(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
3232
.writeValueAsString(duration);
3333

@@ -40,7 +40,7 @@ public void testSerializationAsTimestampNanoseconds02() throws Exception
4040
{
4141
Duration duration = Duration.ofSeconds(13498L, 8374);
4242
String value = WRITER
43-
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
43+
.with(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
4444
.with(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
4545
.writeValueAsString(duration);
4646

@@ -53,7 +53,7 @@ public void testSerializationAsTimestampMilliseconds01() throws Exception
5353
{
5454
Duration duration = Duration.ofSeconds(60L, 0);
5555
String value = WRITER
56-
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
56+
.with(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
5757
.without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
5858
.writeValueAsString(duration);
5959

@@ -66,7 +66,7 @@ public void testSerializationAsTimestampMilliseconds02() throws Exception
6666
{
6767
Duration duration = Duration.ofSeconds(13498L, 8374);
6868
String value = WRITER
69-
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
69+
.with(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
7070
.without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
7171
.writeValueAsString(duration);
7272

@@ -79,7 +79,7 @@ public void testSerializationAsTimestampMilliseconds03() throws Exception
7979
{
8080
Duration duration = Duration.ofSeconds(13498L, 837481723);
8181
String value = WRITER
82-
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
82+
.with(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
8383
.without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
8484
.writeValueAsString(duration);
8585

@@ -92,7 +92,7 @@ public void testSerializationAsString01() throws Exception
9292
{
9393
Duration duration = Duration.ofSeconds(60L, 0);
9494
String value = WRITER
95-
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
95+
.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
9696
.writeValueAsString(duration);
9797

9898
assertNotNull("The value should not be null.", value);
@@ -104,7 +104,7 @@ public void testSerializationAsString02() throws Exception
104104
{
105105
Duration duration = Duration.ofSeconds(13498L, 8374);
106106
String value = WRITER
107-
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
107+
.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
108108
.writeValueAsString(duration);
109109

110110
assertNotNull("The value should not be null.", value);
@@ -115,7 +115,7 @@ public void testSerializationAsString02() throws Exception
115115
public void testSerializationWithTypeInfo01() throws Exception
116116
{
117117
ObjectMapper mapper = newMapperBuilder()
118-
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
118+
.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS,
119119
SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
120120
.addMixIn(TemporalAmount.class, MockObjectConfiguration.class)
121121
.build();
@@ -131,7 +131,7 @@ public void testSerializationWithTypeInfo01() throws Exception
131131
public void testSerializationWithTypeInfo02() throws Exception
132132
{
133133
ObjectMapper mapper = newMapperBuilder()
134-
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
134+
.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
135135
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
136136
.addMixIn(TemporalAmount.class, MockObjectConfiguration.class)
137137
.build();
@@ -147,7 +147,7 @@ public void testSerializationWithTypeInfo02() throws Exception
147147
public void testSerializationWithTypeInfo03() throws Exception
148148
{
149149
ObjectMapper mapper = newMapperBuilder()
150-
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
150+
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
151151
.addMixIn(TemporalAmount.class, MockObjectConfiguration.class)
152152
.build();
153153
Duration duration = Duration.ofSeconds(13498L, 8374);

release-notes/CREDITS renamed to release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ Sonny Gill (sonnygill@github)
3636
#67: `ParameterNamesModule` does not deserialize with a single parameter
3737
constructor when using `SnakeCase` `PropertyNamingStrategy`
3838
(2.9.6)
39+
40+
Kezhu Wang (kezhuw@github)
41+
#75: Use `SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS` for configuring
42+
`Duration` serialization
43+
(2.10.0)

release-notes/VERSION

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
Project: jackson-modules-java8
2+
Versions: 3.x (for earlier, see VERSION-2.x)
23
Modules:
3-
jackson-module-parameter-names
4-
jackson-datatype-jdk8
54
jackson-datatype-jsr310
5+
jackson-datatype-jdk8 (deprecated, no functionality as of 3.0)
6+
jackson-module-parameter-names (deprecated, no functionality as of 3.0)
7+
8+
Contains Date/Time types introduced in Java 8. With Jackson 2.x was separate
9+
module since baseline JDK was not yet Java 8. With Jackson 3.0 kept separate
10+
due to number of types.
611

712
------------------------------------------------------------------------
813
=== Releases ===
@@ -15,77 +20,3 @@ Modules:
1520
- Deprecate "paramater names" and "datatypes" modules as functionality
1621
now included directly in `jackson-databind`
1722
- Remove legacy `JSR310Module`
18-
19-
2.9.6 (12-Jun-2018)
20-
21-
#65: Use `DeserializationContext.handleWeirdXxxValue()` for datetime deserializers
22-
(contributed by Semyon L)
23-
#67: `ParameterNamesModule` does not deserialize with a single parameter
24-
constructor when using `SnakeCase` `PropertyNamingStrategy`
25-
(reported by Sonny G)
26-
27-
2.9.5 (26-Mar-2018)
28-
29-
#98: `OffsetDateTime` with `@JsonFormat(without=...)` doesn't seem to work
30-
(reported by ayush-veem@github)
31-
32-
2.9.4 (24-Jan-2018)
33-
34-
No changes since 2.9.3
35-
36-
2.9.3 (09-Dec-2017)
37-
38-
#46: Double array serialization of `LocalDate` stored as an object with
39-
wrapper object typing enabled
40-
(reported by unintended@github)
41-
- Improve error reporting for `LocalDateTime`, `LocalTime`, `OffsetTime` for
42-
timestamp input (JSON integer value)
43-
44-
2.9.2 (14-Oct-2017)
45-
2.9.1 (07-Sep-2017)
46-
47-
No changes since 2.9.0
48-
49-
2.9.0 (30-Jul-2017)
50-
51-
#3: (datatype) Add Serialization Support for Streams
52-
(contributed by Julien B)
53-
#20: (datetime) Allow `LocalDate` to be serialized/deserialized as number (epoch day)
54-
(contributed by João C)
55-
#21: (datetime) `DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS` not respected
56-
(contributed by JP Moresmau)
57-
58-
2.8.10 (not yet released)
59-
60-
#33: `Jdk8Serializer.findReferenceSerializer()` leads to `StackOverflowError` in 2.8.9
61-
(reported by Mikko T)
62-
63-
2.8.9 (12-Jun-2017)
64-
65-
No changes since 2.8.8
66-
67-
2.8.8 (05-Apr-2017)
68-
69-
#13: (datatype) `configureAbsentsAsNulls` not working for primitive optionals
70-
like `OptionalInt`
71-
(reported by Louis-Rémi P)
72-
#15: (datatype) Optional<Long> and OptionalLong deserialization are not consistent
73-
when deserializing from String
74-
(reported by Louis-Rémi P)
75-
#17: (datatype) Cached `Optional` serializer does not apply annotations for POJO properties
76-
(reported by codicusmaximus@github)
77-
#18: (datetime) `InstantDeserializer` is not working with offset of zero `+00:00` and `+00`
78-
(contributed by kevinjom@github)
79-
80-
2.8.7 (21-Feb-2017)
81-
2.8.6 (12-Jan-2017)
82-
83-
No changes since 2.8.5
84-
85-
2.8.5 (14-Nov-2016)
86-
87-
The very first release from this repository!
88-
89-
#89: If the JsonFormat pattern is all numeric, the `InstantDeserializer` will
90-
do the wrong thing
91-
(reported, contributed fix, by ubik2@github)

release-notes/VERSION-2.x

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Project: jackson-modules-java8
2+
Modules:
3+
jackson-module-parameter-names
4+
jackson-datatype-jdk8
5+
jackson-datatype-jsr310
6+
7+
------------------------------------------------------------------------
8+
=== Releases ===
9+
------------------------------------------------------------------------
10+
11+
2.10.0 (not yet released)
12+
13+
#75: Use `SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS` for configuring
14+
`Duration` serialization
15+
(suggested by Kezhu W)
16+
17+
2.9.7 (not yet released)
18+
19+
2.9.6 (12-Jun-2018)
20+
21+
#65: Use `DeserializationContext.handleWeirdXxxValue()` for datetime deserializers
22+
(contributed by Semyon L)
23+
#67: `ParameterNamesModule` does not deserialize with a single parameter
24+
constructor when using `SnakeCase` `PropertyNamingStrategy`
25+
(reported by Sonny G)
26+
27+
2.9.5 (26-Mar-2018)
28+
29+
#98: `OffsetDateTime` with `@JsonFormat(without=...)` doesn't seem to work
30+
(reported by ayush-veem@github)
31+
32+
2.9.4 (24-Jan-2018)
33+
34+
No changes since 2.9.3
35+
36+
2.9.3 (09-Dec-2017)
37+
38+
#46: Double array serialization of `LocalDate` stored as an object with
39+
wrapper object typing enabled
40+
(reported by unintended@github)
41+
- Improve error reporting for `LocalDateTime`, `LocalTime`, `OffsetTime` for
42+
timestamp input (JSON integer value)
43+
44+
2.9.2 (14-Oct-2017)
45+
2.9.1 (07-Sep-2017)
46+
47+
No changes since 2.9.0
48+
49+
2.9.0 (30-Jul-2017)
50+
51+
#3: (datatype) Add Serialization Support for Streams
52+
(contributed by Julien B)
53+
#20: (datetime) Allow `LocalDate` to be serialized/deserialized as number (epoch day)
54+
(contributed by João C)
55+
#21: (datetime) `DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS` not respected
56+
(contributed by JP Moresmau)
57+
58+
2.8.10 (not yet released)
59+
60+
#33: `Jdk8Serializer.findReferenceSerializer()` leads to `StackOverflowError` in 2.8.9
61+
(reported by Mikko T)
62+
63+
2.8.9 (12-Jun-2017)
64+
65+
No changes since 2.8.8
66+
67+
2.8.8 (05-Apr-2017)
68+
69+
#13: (datatype) `configureAbsentsAsNulls` not working for primitive optionals
70+
like `OptionalInt`
71+
(reported by Louis-Rémi P)
72+
#15: (datatype) Optional<Long> and OptionalLong deserialization are not consistent
73+
when deserializing from String
74+
(reported by Louis-Rémi P)
75+
#17: (datatype) Cached `Optional` serializer does not apply annotations for POJO properties
76+
(reported by codicusmaximus@github)
77+
#18: (datetime) `InstantDeserializer` is not working with offset of zero `+00:00` and `+00`
78+
(contributed by kevinjom@github)
79+
80+
2.8.7 (21-Feb-2017)
81+
2.8.6 (12-Jan-2017)
82+
83+
No changes since 2.8.5
84+
85+
2.8.5 (14-Nov-2016)
86+
87+
The very first release from this repository!
88+
89+
#89: If the JsonFormat pattern is all numeric, the `InstantDeserializer` will
90+
do the wrong thing
91+
(reported, contributed fix, by ubik2@github)

0 commit comments

Comments
 (0)