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
@@ -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));