Skip to content

Commit 275e054

Browse files
committed
Fix #75
1 parent bf2e8dc commit 275e054

File tree

10 files changed

+62
-34
lines changed

10 files changed

+62
-34
lines changed

datatypes/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.fasterxml.jackson.module</groupId>
66
<artifactId>jackson-modules-java8</artifactId>
7-
<version>2.9.7-SNAPSHOT</version>
7+
<version>2.10.0-SNAPSHOT</version>
88
</parent>
99
<groupId>com.fasterxml.jackson.datatype</groupId>
1010
<artifactId>jackson-datatype-jdk8</artifactId>

datetime/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.fasterxml.jackson.module</groupId>
66
<artifactId>jackson-modules-java8</artifactId>
7-
<version>2.9.7-SNAPSHOT</version>
7+
<version>2.10.0-SNAPSHOT</version>
88
</parent>
99
<groupId>com.fasterxml.jackson.datatype</groupId>
1010
<artifactId>jackson-datatype-jsr310</artifactId>

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,18 @@
8888
* </pre>
8989
*<p>
9090
* Note that as of 2.x, if auto-registering modules, this package will register
91-
* legacy version, {@link JSR310Module}, and NOT this module. 3.x will change the efaults.
91+
* legacy version, {@link JSR310Module}, and NOT this module. 3.x will change the default.
9292
* Legacy version has the same functionality, but slightly different default configuration:
9393
* see {@link com.fasterxml.jackson.datatype.jsr310.JSR310Module} for details.
9494
*<p>
9595
* Most {@code java.time} types are serialized as numbers (integers or decimals as appropriate) if the
96-
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} feature is enabled, and otherwise are serialized in
97-
* standard <a href="http://en.wikipedia.org/wiki/ISO_8601" target="_blank">ISO-8601</a> string representation. ISO-8601 specifies formats
98-
* for representing offset dates and times, zoned dates and times, local dates and times, periods, durations, zones, and more. All
99-
* {@code java.time} types have built-in translation to and from ISO-8601 formats.
96+
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATES_AS_TIMESTAMPS} feature is enabled
97+
* (or, for {@link Duration}, {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DURATIONS_AS_TIMESTAMPS}),
98+
* and otherwise are serialized in standard
99+
* <a href="http://en.wikipedia.org/wiki/ISO_8601" target="_blank">ISO-8601</a> string representation.
100+
* ISO-8601 specifies formats for representing offset dates and times, zoned dates and times,
101+
* local dates and times, periods, durations, zones, and more. All {@code java.time} types
102+
* have built-in translation to and from ISO-8601 formats.
100103
* <p>
101104
* Granularity of timestamps is controlled through the companion features
102105
* {@link com.fasterxml.jackson.databind.SerializationFeature#WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS} and
@@ -155,7 +158,6 @@ public JavaTimeModule()
155158
addDeserializer(ZoneId.class, JSR310StringParsableDeserializer.ZONE_ID);
156159
addDeserializer(ZoneOffset.class, JSR310StringParsableDeserializer.ZONE_OFFSET);
157160

158-
159161
// then serializers:
160162
addSerializer(Duration.class, DurationSerializer.INSTANCE);
161163
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
@@ -62,7 +69,13 @@ protected DurationSerializer(DurationSerializer base,
6269
protected DurationSerializer withFormat(Boolean useTimestamp, DateTimeFormatter dtf, JsonFormat.Shape shape) {
6370
return new DurationSerializer(this, useTimestamp, dtf);
6471
}
65-
72+
73+
// @since 2.10
74+
@Override
75+
protected SerializationFeature getTimestampsFeature() {
76+
return SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS;
77+
}
78+
6679
@Override
6780
public void serialize(Duration duration, JsonGenerator generator, SerializerProvider provider) throws IOException
6881
{

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
@@ -194,6 +194,20 @@ protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaTyp
194194
}
195195
}
196196

197+
/**
198+
* Overridable method that determines {@link SerializationFeature} that is used as
199+
* the global default in determining if date/time value serialized should use numeric
200+
* format ("timestamp") or not.
201+
*<p>
202+
* Note that this feature is just the baseline setting and may be overridden on per-type
203+
* or per-property basis.
204+
*
205+
* @since 2.10
206+
*/
207+
protected SerializationFeature getTimestampsFeature() {
208+
return SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
209+
}
210+
197211
protected boolean useTimestamp(SerializerProvider provider) {
198212
if (_useTimestamp != null) {
199213
return _useTimestamp.booleanValue();
@@ -207,7 +221,7 @@ protected boolean useTimestamp(SerializerProvider provider) {
207221
}
208222
}
209223
// assume that explicit formatter definition implies use of textual format
210-
return _formatter == null && provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
224+
return (_formatter == null) && provider.isEnabled(getTimestampsFeature());
211225
}
212226

213227
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 = newMapper(); // need new to add mix-ins:
118-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
118+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, true);
119119
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, true);
120120
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
121121
Duration duration = Duration.ofSeconds(13498L, 8374);
@@ -130,7 +130,7 @@ public void testSerializationWithTypeInfo01() throws Exception
130130
public void testSerializationWithTypeInfo02() throws Exception
131131
{
132132
ObjectMapper mapper = newMapper(); // need new to add mix-ins:
133-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
133+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, true);
134134
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
135135
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
136136
Duration duration = Duration.ofSeconds(13498L, 837481723);
@@ -145,7 +145,7 @@ public void testSerializationWithTypeInfo02() throws Exception
145145
public void testSerializationWithTypeInfo03() throws Exception
146146
{
147147
ObjectMapper mapper = newMapper(); // need new to add mix-ins:
148-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
148+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
149149
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
150150
Duration duration = Duration.ofSeconds(13498L, 8374);
151151
String value = mapper.writeValueAsString(duration);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.junit.Test;
1414

1515
import java.io.IOException;
16-
import java.time.LocalDate;
1716
import java.time.LocalDateTime;
1817
import java.time.Month;
1918
import java.time.format.DateTimeParseException;

datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/old/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

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

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

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

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

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

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

111111
assertNotNull("The value should not be null.", value);
@@ -116,7 +116,7 @@ public void testSerializationAsString02() throws Exception
116116
public void testSerializationWithTypeInfo01() throws Exception
117117
{
118118
ObjectMapper mapper = newMapper(); // need new to add mix-ins:
119-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
119+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, true);
120120
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, true);
121121
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
122122
Duration duration = Duration.ofSeconds(13498L, 8374);
@@ -131,7 +131,7 @@ public void testSerializationWithTypeInfo01() throws Exception
131131
public void testSerializationWithTypeInfo02() throws Exception
132132
{
133133
ObjectMapper mapper = newMapper(); // need new to add mix-ins:
134-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
134+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, true);
135135
mapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
136136
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
137137
Duration duration = Duration.ofSeconds(13498L, 837481723);
@@ -146,7 +146,7 @@ public void testSerializationWithTypeInfo02() throws Exception
146146
public void testSerializationWithTypeInfo03() throws Exception
147147
{
148148
ObjectMapper mapper = newMapper(); // need new to add mix-ins:
149-
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
149+
mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
150150
mapper.addMixIn(TemporalAmount.class, MockObjectConfiguration.class);
151151
Duration duration = Duration.ofSeconds(13498L, 8374);
152152
String value = mapper.writeValueAsString(duration);

parameter-names/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.fasterxml.jackson.module</groupId>
66
<artifactId>jackson-modules-java8</artifactId>
7-
<version>2.9.7-SNAPSHOT</version>
7+
<version>2.10.0-SNAPSHOT</version>
88
</parent>
99
<artifactId>jackson-module-parameter-names</artifactId>
1010
<name>Jackson-module-parameter-names</name>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<parent>
44
<groupId>com.fasterxml.jackson</groupId>
55
<artifactId>jackson-base</artifactId>
6-
<version>2.9.6</version>
6+
<version>2.10.0-SNAPSHOT</version>
77
</parent>
88
<groupId>com.fasterxml.jackson.module</groupId>
99
<artifactId>jackson-modules-java8</artifactId>
1010
<name>Jackson modules: Java 8</name>
11-
<version>2.9.7-SNAPSHOT</version>
11+
<version>2.10.0-SNAPSHOT</version>
1212
<packaging>pom</packaging>
1313
<description>Parent pom for Jackson modules needed to support Java 8 features and types
1414
</description>

0 commit comments

Comments
 (0)