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:
2026-12-03 23:44:16 +05:30
co-authored by Claude Sonnet 5.5
parent f97ec4e014
commit 6ba018c61d
5 changed files with 13 additions and 0 deletions
+1
View File
@@ -50,5 +50,6 @@
== @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"}
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"}
London, CONTEXT_TIME_ZONE disabled: {"offset":"2026-12-15 10:30 +05:30","zoned":"2026-12-15 10:30 +05:30"}
+1
View File
@@ -10,4 +10,5 @@ Jackson 3, ONE_BASED_MONTHS off : {"month":10}
Jackson 3, Month override STRING : {"month":"NOVEMBER"}
Jackson 3 reads it : NOVEMBER
Jackson 2 reads it : NOVEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"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 reads it : NOVEMBER
Jackson 2 reads it : DECEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"month":11}
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
######## 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 reads it : NOVEMBER
Jackson 2 reads it : DECEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"month":11}
Jackson 3, MonthNameSerializer : {"month":"NOVEMBER"}
######## 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 reads it : NOVEMBER
Jackson 2 reads it : NOVEMBER
Jackson 3, @JsonFormat(shape=STRING) : {"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("mapper zone not set : "
+ 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) : "
+ JsonMapper.builder().defaultTimeZone(london).build().writeValueAsString(p));
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. */
public class T11MonthTrap {
record Report(Month month) { }
record Annotated(@JsonFormat(shape = JsonFormat.Shape.STRING) Month month) { }
public static void main(String[] args) throws Exception {
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 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());
System.out.println("Jackson 3, MonthNameSerializer : "
+ JsonMapper.builder().addModule(module).build().writeValueAsString(november));