Skip to content

Commit 07422d3

Browse files
committed
Further default change for 3.0 wrt #2643 (+00:00 -> Z)
1 parent b81afe0 commit 07422d3

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,9 @@ protected void _format(TimeZone tz, Locale loc, Date date,
417417
}
418418
pad2(buffer, minutes);
419419
} else {
420-
// 24-Jun-2017, tatu: While `Z` would be conveniently short, older specs
421-
// mandate use of full `+0000`
422-
// 06-Mar-2020, tatu: Actually statement should read "for compatibility reasons"
423-
// and not standards (unless it is wrt RFC-1123). This will change in 3.0 at latest
424-
// formatted.append('Z');
425-
if (_tzSerializedWithColon) {
426-
buffer.append("+00:00");
427-
} else {
428-
buffer.append("+0000");
429-
}
420+
// 06-Mar-2020, tatu: Jackson versions 2.x forced use of numeric offset even
421+
// for Zulu; for 3.0 `Z` is used.
422+
buffer.append('Z');
430423
}
431424
}
432425

src/test/java/com/fasterxml/jackson/databind/ser/jdk/DateSerializationTest.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,25 @@ public void testDateISO8601() throws IOException
110110
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
111111
.build();
112112

113-
serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+00:00");
114-
serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+00:00");
115-
serialize(mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+00:00");
116-
serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+00:00");
113+
serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z");
114+
serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z");
115+
serialize(mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z");
116+
serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z");
117117

118118
// 22-Nov-2018, tatu: Also ensure we use padding...
119-
serialize(mapper, judate(911, 1, 1, 00, 00, 00, 0, "UTC"), "0911-01-01T00:00:00.000+00:00");
120-
serialize(mapper, judate(87, 1, 1, 00, 00, 00, 0, "UTC"), "0087-01-01T00:00:00.000+00:00");
121-
serialize(mapper, judate(1, 1, 1, 00, 00, 00, 0, "UTC"), "0001-01-01T00:00:00.000+00:00");
119+
serialize(mapper, judate(911, 1, 1, 00, 00, 00, 0, "UTC"), "0911-01-01T00:00:00.000Z");
120+
serialize(mapper, judate(87, 1, 1, 00, 00, 00, 0, "UTC"), "0087-01-01T00:00:00.000Z");
121+
serialize(mapper, judate(1, 1, 1, 00, 00, 00, 0, "UTC"), "0001-01-01T00:00:00.000Z");
122122
}
123123

124124
// [databind#2167]: beyond year 9999 needs special handling
125125
public void testDateISO8601_10k() throws IOException
126126
{
127127
ObjectWriter w = MAPPER.writer()
128128
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
129-
serialize(w, judate(10204, 1, 1, 00, 00, 00, 0, "UTC"), "+10204-01-01T00:00:00.000+00:00");
129+
serialize(w, judate(10204, 1, 1, 00, 00, 00, 0, "UTC"), "+10204-01-01T00:00:00.000Z");
130130
// and although specification lacks for beyond 5 digits (well, actually even 5...), let's do our best:
131-
serialize(w, judate(123456, 1, 1, 00, 00, 00, 0, "UTC"), "+123456-01-01T00:00:00.000+00:00");
131+
serialize(w, judate(123456, 1, 1, 00, 00, 00, 0, "UTC"), "+123456-01-01T00:00:00.000Z");
132132
}
133133

134134
// [databind#2167]: dates before Common Era (CE), that is, BCE, need special care:
@@ -140,10 +140,10 @@ public void testDateISO8601_BCE() throws IOException
140140
// First: I _think_ BCE-1 is what you get with year 0, and should become "+0000"
141141
// and from further back in time, it'll be "-0001" (BCE-2) etc)
142142

143-
serialize(w, judate(0, 1, 1, 00, 00, 00, 0, "UTC"), "+0000-01-01T00:00:00.000+00:00");
144-
serialize(w, judate(-1, 1, 1, 00, 00, 00, 0, "UTC"), "-0001-01-01T00:00:00.000+00:00");
145-
serialize(w, judate(-49, 1, 1, 00, 00, 00, 0, "UTC"), "-0049-01-01T00:00:00.000+00:00"); // All hail Caesar
146-
serialize(w, judate(-264, 1, 1, 00, 00, 00, 0, "UTC"), "-0264-01-01T00:00:00.000+00:00"); // Carthage FTW?
143+
serialize(w, judate(0, 1, 1, 00, 00, 00, 0, "UTC"), "+0000-01-01T00:00:00.000Z");
144+
serialize(w, judate(-1, 1, 1, 00, 00, 00, 0, "UTC"), "-0001-01-01T00:00:00.000Z");
145+
serialize(w, judate(-49, 1, 1, 00, 00, 00, 0, "UTC"), "-0049-01-01T00:00:00.000Z"); // All hail Caesar
146+
serialize(w, judate(-264, 1, 1, 00, 00, 00, 0, "UTC"), "-0264-01-01T00:00:00.000Z"); // Carthage FTW?
147147
}
148148

149149
/**
@@ -177,8 +177,8 @@ public void testDateISO8601_colonInTZ() throws IOException
177177
.defaultDateFormat(dateFormat)
178178
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
179179
.build();
180-
serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+0000");
181-
serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+0000");
180+
serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z");
181+
serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z");
182182
}
183183

184184
public void testDateOther() throws IOException
@@ -230,7 +230,7 @@ public void testDatesAsMapKeys() throws IOException
230230
assertFalse(mapper.isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS));
231231
map.put(new Date(0L), Integer.valueOf(1));
232232
// by default will serialize as ISO-8601 values...
233-
assertEquals("{\"1970-01-01T00:00:00.000+00:00\":1}", mapper.writeValueAsString(map));
233+
assertEquals("{\"1970-01-01T00:00:00.000Z\":1}", mapper.writeValueAsString(map));
234234

235235
// but can change to use timestamps too
236236
mapper = jsonMapperBuilder()
@@ -264,7 +264,7 @@ public void testDateWithJsonFormat() throws Exception
264264

265265
// and with default (ISO8601) format (databind#1109)
266266
json = MAPPER.writeValueAsString(new DateAsDefaultStringBean(0L));
267-
assertEquals("{\"date\":\"1970-01-01T00:00:00.000+00:00\"}", json);
267+
assertEquals("{\"date\":\"1970-01-01T00:00:00.000Z\"}", json);
268268
}
269269

270270
/**
@@ -313,7 +313,7 @@ public void testDateDefaultShape() throws Exception
313313
json = MAPPER.writer()
314314
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
315315
.writeValueAsString(new DateAsDefaultBean(0L));
316-
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json);
316+
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json);
317317

318318
// Empty @JsonFormat => default to user config
319319
json = MAPPER.writer()
@@ -323,7 +323,7 @@ public void testDateDefaultShape() throws Exception
323323
json = MAPPER.writer()
324324
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
325325
.writeValueAsString(new DateAsDefaultBeanWithEmptyJsonFormat(0L));
326-
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json);
326+
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json);
327327

328328
// @JsonFormat with Shape.ANY and pattern => STRING shape, regardless of user config
329329
json = MAPPER.writer()
@@ -339,11 +339,11 @@ public void testDateDefaultShape() throws Exception
339339
json = MAPPER.writer()
340340
.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
341341
.writeValueAsString(new DateAsDefaultBeanWithLocale(0L));
342-
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json);
342+
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json);
343343
json = MAPPER.writer()
344344
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
345345
.writeValueAsString(new DateAsDefaultBeanWithLocale(0L));
346-
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json);
346+
assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json);
347347

348348
// @JsonFormat with Shape.ANY and timezone => STRING shape, regardless of user config
349349
json = MAPPER.writer()

0 commit comments

Comments
 (0)