Closed mike-reynolds-savient closed 8 months ago
Is this the serializer and have you registered the related module ?
Yep, that's the one. Note that this issue also effects com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer
@mike-reynolds-savient you repeated back the name of the class that I sent - did you mean to name a different class?
Apologies - LocalDateTimeSerializer
Version 2.14.2 is not the latest so would be good repro with 2.16.0.
But also if this requires use of Java 8 Date/Time types, need to move to different repo; jackson-databind
tests cannot depend on Java 8 date/time module (cyclic dependency). Will move the isse.
Ok, so, couple of things now that I re-read this again.
First: I can definitely avoid NPE for LocalDate[Time]Serializer
, and that probably makes sense.
But second, I think that DEDUCTION
based type deserializer can only work JSON Object represenations, not String-valued ones. So it can work to figure out type of POJOs, but not LocalDate
or LocalDateTime
. So ultimately I am not sure this can be made to work, if I understand use case correctly (I might misunderstand it tho).
Was able to reproduce (must force serialization as String), partial fix via #298, will try to cover all types for which NPE would be produced.
@mike-reynolds-savient I fixed the NPE part for 2.16(.2) -- although it will be a month or two until that release. If you can try 2.16.2-SNAPSHOT to see how things work that'd be good. I am not confident DEDUCTION will work in general, but at least it should not fail with NPE no matter what.
Many thanks @cowtowncoder When 2.16.2 or 2.17 become available for download I'll give it a go again. (I can't get to the -SNAPSHOT)
Search before asking
Describe the bug
In v2.14.2 AsDeductionTypeSerializer was introduced. Prior to this we could define an immutable interface as follows:
and set a value of LocalDate, LocalDateTime, OffsetDateTime etc as the return of
getValue()
This would serialize correctly with
JsonMapper.builder().disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
set.We now get a "Cannot read field 'valueShape'" exception because
AsDeductionTypeSerializer
returns null if theWritableTypeId.valueShape
is not a structure start token. This results in an NPE within theLocalDateTimeSerializer
class on line 89;Version Information
2.14.2
Reproduction
Expected behavior
If deduction cannot find the class it should return default property behaviour.
Additional context
https://github.com/FasterXML/jackson-databind/issues/3711#issuecomment-1371580012