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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user