java-time: add @JsonFormat(shape=STRING) Month line across versions and a JVM-zone control for patterned offsets
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4HkWoC7hLzk61vZa8
This commit is contained in:
@@ -50,5 +50,6 @@
|
|||||||
|
|
||||||
== @JsonFormat(pattern) on offset types, values are at +05:30
|
== @JsonFormat(pattern) on offset types, values are at +05:30
|
||||||
mapper zone not set : {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
|
mapper zone not set : {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
|
||||||
|
not set, JVM zone New York : {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
|
||||||
defaultTimeZone(Europe/London) : {"offset":"2026-12-15 05:00 Z","zoned":"2026-12-15 05:00 Z"}
|
defaultTimeZone(Europe/London) : {"offset":"2026-12-15 05:00 Z","zoned":"2026-12-15 05:00 Z"}
|
||||||
London, CONTEXT_TIME_ZONE disabled: {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
|
London, CONTEXT_TIME_ZONE disabled: {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
|
||||||
|
|||||||
@@ -10,4 +10,5 @@ Jackson 3, ONE_BASED_MONTHS off : {"month":10}
|
|||||||
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
|
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
|
||||||
Jackson 3 reads it : NOVEMBER
|
Jackson 3 reads it : NOVEMBER
|
||||||
Jackson 2 reads it : NOVEMBER
|
Jackson 2 reads it : NOVEMBER
|
||||||
|
Jackson 3, @JsonFormat(shape=STRING) : {"month":"NOVEMBER"}
|
||||||
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Jackson 3, ONE_BASED_MONTHS off : {"month":10}
|
|||||||
Jackson 3, Month override STRING : {"month":11}
|
Jackson 3, Month override STRING : {"month":11}
|
||||||
Jackson 3 reads it : NOVEMBER
|
Jackson 3 reads it : NOVEMBER
|
||||||
Jackson 2 reads it : DECEMBER
|
Jackson 2 reads it : DECEMBER
|
||||||
|
Jackson 3, @JsonFormat(shape=STRING) : {"month":11}
|
||||||
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
||||||
|
|
||||||
######## Jackson 3.2.4
|
######## Jackson 3.2.4
|
||||||
@@ -26,6 +27,7 @@ Jackson 3, ONE_BASED_MONTHS off : {"month":10}
|
|||||||
Jackson 3, Month override STRING : {"month":11}
|
Jackson 3, Month override STRING : {"month":11}
|
||||||
Jackson 3 reads it : NOVEMBER
|
Jackson 3 reads it : NOVEMBER
|
||||||
Jackson 2 reads it : DECEMBER
|
Jackson 2 reads it : DECEMBER
|
||||||
|
Jackson 3, @JsonFormat(shape=STRING) : {"month":11}
|
||||||
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
||||||
|
|
||||||
######## Jackson 3.3.0
|
######## Jackson 3.3.0
|
||||||
@@ -41,5 +43,6 @@ Jackson 3, ONE_BASED_MONTHS off : {"month":10}
|
|||||||
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
|
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
|
||||||
Jackson 3 reads it : NOVEMBER
|
Jackson 3 reads it : NOVEMBER
|
||||||
Jackson 2 reads it : NOVEMBER
|
Jackson 2 reads it : NOVEMBER
|
||||||
|
Jackson 3, @JsonFormat(shape=STRING) : {"month":"NOVEMBER"}
|
||||||
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ public class T05TimeZones {
|
|||||||
System.out.println("== @JsonFormat(pattern) on offset types, values are at +05:30");
|
System.out.println("== @JsonFormat(pattern) on offset types, values are at +05:30");
|
||||||
System.out.println("mapper zone not set : "
|
System.out.println("mapper zone not set : "
|
||||||
+ JsonMapper.builder().build().writeValueAsString(p));
|
+ JsonMapper.builder().build().writeValueAsString(p));
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
|
||||||
|
System.out.println("not set, JVM zone New York : "
|
||||||
|
+ JsonMapper.builder().build().writeValueAsString(p));
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
System.out.println("defaultTimeZone(Europe/London) : "
|
System.out.println("defaultTimeZone(Europe/London) : "
|
||||||
+ JsonMapper.builder().defaultTimeZone(london).build().writeValueAsString(p));
|
+ JsonMapper.builder().defaultTimeZone(london).build().writeValueAsString(p));
|
||||||
System.out.println("London, CONTEXT_TIME_ZONE disabled: "
|
System.out.println("London, CONTEXT_TIME_ZONE disabled: "
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import tools.jackson.databind.ser.std.StdSerializer;
|
|||||||
/** java.time.Month changed from a name to a number, and the number can be off by one. */
|
/** java.time.Month changed from a name to a number, and the number can be off by one. */
|
||||||
public class T11MonthTrap {
|
public class T11MonthTrap {
|
||||||
record Report(Month month) { }
|
record Report(Month month) { }
|
||||||
|
record Annotated(@JsonFormat(shape = JsonFormat.Shape.STRING) Month month) { }
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
ObjectMapper j2 = new ObjectMapper().registerModule(new JavaTimeModule());
|
ObjectMapper j2 = new ObjectMapper().registerModule(new JavaTimeModule());
|
||||||
@@ -47,6 +48,9 @@ public class T11MonthTrap {
|
|||||||
System.out.println(" Jackson 3 reads it : " + names.readValue(named, Report.class).month());
|
System.out.println(" Jackson 3 reads it : " + names.readValue(named, Report.class).month());
|
||||||
System.out.println(" Jackson 2 reads it : " + j2.readValue(named, Report.class).month());
|
System.out.println(" Jackson 2 reads it : " + j2.readValue(named, Report.class).month());
|
||||||
|
|
||||||
|
System.out.println("Jackson 3, @JsonFormat(shape=STRING) : "
|
||||||
|
+ j3.writeValueAsString(new Annotated(Month.NOVEMBER)));
|
||||||
|
|
||||||
SimpleModule module = new SimpleModule().addSerializer(Month.class, new MonthNameSerializer());
|
SimpleModule module = new SimpleModule().addSerializer(Month.class, new MonthNameSerializer());
|
||||||
System.out.println("Jackson 3, MonthNameSerializer : "
|
System.out.println("Jackson 3, MonthNameSerializer : "
|
||||||
+ JsonMapper.builder().addModule(module).build().writeValueAsString(november));
|
+ JsonMapper.builder().addModule(module).build().writeValueAsString(november));
|
||||||
|
|||||||
Reference in New Issue
Block a user