diff --git a/src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java b/src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java index cdbde541d8..c20e63cbb5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java +++ b/src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java @@ -417,16 +417,9 @@ protected void _format(TimeZone tz, Locale loc, Date date, } pad2(buffer, minutes); } else { - // 24-Jun-2017, tatu: While `Z` would be conveniently short, older specs - // mandate use of full `+0000` - // 06-Mar-2020, tatu: Actually statement should read "for compatibility reasons" - // and not standards (unless it is wrt RFC-1123). This will change in 3.0 at latest -// formatted.append('Z'); - if (_tzSerializedWithColon) { - buffer.append("+00:00"); - } else { - buffer.append("+0000"); - } + // 06-Mar-2020, tatu: Jackson versions 2.x forced use of numeric offset even + // for Zulu; for 3.0 `Z` is used. + buffer.append('Z'); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/DateSerializationTest.java b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/DateSerializationTest.java index d3f95827db..15939396e2 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/DateSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/DateSerializationTest.java @@ -110,15 +110,15 @@ public void testDateISO8601() throws IOException .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .build(); - serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+00:00"); - serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+00:00"); - serialize(mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+00:00"); - serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+00:00"); + serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z"); + serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z"); + serialize(mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z"); + serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z"); // 22-Nov-2018, tatu: Also ensure we use padding... - serialize(mapper, judate(911, 1, 1, 00, 00, 00, 0, "UTC"), "0911-01-01T00:00:00.000+00:00"); - serialize(mapper, judate(87, 1, 1, 00, 00, 00, 0, "UTC"), "0087-01-01T00:00:00.000+00:00"); - serialize(mapper, judate(1, 1, 1, 00, 00, 00, 0, "UTC"), "0001-01-01T00:00:00.000+00:00"); + serialize(mapper, judate(911, 1, 1, 00, 00, 00, 0, "UTC"), "0911-01-01T00:00:00.000Z"); + serialize(mapper, judate(87, 1, 1, 00, 00, 00, 0, "UTC"), "0087-01-01T00:00:00.000Z"); + serialize(mapper, judate(1, 1, 1, 00, 00, 00, 0, "UTC"), "0001-01-01T00:00:00.000Z"); } // [databind#2167]: beyond year 9999 needs special handling @@ -126,9 +126,9 @@ public void testDateISO8601_10k() throws IOException { ObjectWriter w = MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - serialize(w, judate(10204, 1, 1, 00, 00, 00, 0, "UTC"), "+10204-01-01T00:00:00.000+00:00"); + serialize(w, judate(10204, 1, 1, 00, 00, 00, 0, "UTC"), "+10204-01-01T00:00:00.000Z"); // and although specification lacks for beyond 5 digits (well, actually even 5...), let's do our best: - serialize(w, judate(123456, 1, 1, 00, 00, 00, 0, "UTC"), "+123456-01-01T00:00:00.000+00:00"); + serialize(w, judate(123456, 1, 1, 00, 00, 00, 0, "UTC"), "+123456-01-01T00:00:00.000Z"); } // [databind#2167]: dates before Common Era (CE), that is, BCE, need special care: @@ -140,10 +140,10 @@ public void testDateISO8601_BCE() throws IOException // First: I _think_ BCE-1 is what you get with year 0, and should become "+0000" // and from further back in time, it'll be "-0001" (BCE-2) etc) - serialize(w, judate(0, 1, 1, 00, 00, 00, 0, "UTC"), "+0000-01-01T00:00:00.000+00:00"); - serialize(w, judate(-1, 1, 1, 00, 00, 00, 0, "UTC"), "-0001-01-01T00:00:00.000+00:00"); - serialize(w, judate(-49, 1, 1, 00, 00, 00, 0, "UTC"), "-0049-01-01T00:00:00.000+00:00"); // All hail Caesar - serialize(w, judate(-264, 1, 1, 00, 00, 00, 0, "UTC"), "-0264-01-01T00:00:00.000+00:00"); // Carthage FTW? + serialize(w, judate(0, 1, 1, 00, 00, 00, 0, "UTC"), "+0000-01-01T00:00:00.000Z"); + serialize(w, judate(-1, 1, 1, 00, 00, 00, 0, "UTC"), "-0001-01-01T00:00:00.000Z"); + serialize(w, judate(-49, 1, 1, 00, 00, 00, 0, "UTC"), "-0049-01-01T00:00:00.000Z"); // All hail Caesar + serialize(w, judate(-264, 1, 1, 00, 00, 00, 0, "UTC"), "-0264-01-01T00:00:00.000Z"); // Carthage FTW? } /** @@ -177,8 +177,8 @@ public void testDateISO8601_colonInTZ() throws IOException .defaultDateFormat(dateFormat) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .build(); - serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000+0000"); - serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000+0000"); + serialize( mapper, judate(1970, 1, 1, 02, 00, 00, 0, "GMT+2"), "1970-01-01T00:00:00.000Z"); + serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"), "1970-01-01T00:00:00.000Z"); } public void testDateOther() throws IOException @@ -230,7 +230,7 @@ public void testDatesAsMapKeys() throws IOException assertFalse(mapper.isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)); map.put(new Date(0L), Integer.valueOf(1)); // by default will serialize as ISO-8601 values... - assertEquals("{\"1970-01-01T00:00:00.000+00:00\":1}", mapper.writeValueAsString(map)); + assertEquals("{\"1970-01-01T00:00:00.000Z\":1}", mapper.writeValueAsString(map)); // but can change to use timestamps too mapper = jsonMapperBuilder() @@ -264,7 +264,7 @@ public void testDateWithJsonFormat() throws Exception // and with default (ISO8601) format (databind#1109) json = MAPPER.writeValueAsString(new DateAsDefaultStringBean(0L)); - assertEquals("{\"date\":\"1970-01-01T00:00:00.000+00:00\"}", json); + assertEquals("{\"date\":\"1970-01-01T00:00:00.000Z\"}", json); } /** @@ -313,7 +313,7 @@ public void testDateDefaultShape() throws Exception json = MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(new DateAsDefaultBean(0L)); - assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json); + assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json); // Empty @JsonFormat => default to user config json = MAPPER.writer() @@ -323,7 +323,7 @@ public void testDateDefaultShape() throws Exception json = MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(new DateAsDefaultBeanWithEmptyJsonFormat(0L)); - assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json); + assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json); // @JsonFormat with Shape.ANY and pattern => STRING shape, regardless of user config json = MAPPER.writer() @@ -339,11 +339,11 @@ public void testDateDefaultShape() throws Exception json = MAPPER.writer() .with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(new DateAsDefaultBeanWithLocale(0L)); - assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json); + assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json); json = MAPPER.writer() .without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .writeValueAsString(new DateAsDefaultBeanWithLocale(0L)); - assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000+00:00'}"), json); + assertEquals(aposToQuotes("{'date':'1970-01-01T00:00:00.000Z'}"), json); // @JsonFormat with Shape.ANY and timezone => STRING shape, regardless of user config json = MAPPER.writer()