JSON argument source fails with LocalDate property deserialization
See original GitHub issueFor some odd reason I get an exception while deserializing java.time.LocalDate
properties:
Failed to convert to type class com.foo.bar.MyClass
java.io.UncheckedIOException: Failed to convert to type class com.foo.bar.MyClass
at org.junitpioneer.jupiter.json.JacksonNode.toType(JacksonNode.java:51)
at org.junitpioneer.jupiter.json.JacksonNode.value(JacksonNode.java:85)
...
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.foo.bar.MyClass["someDate"])
The JSR-310 Jackson datatype dependency is in the classpath, but upon further inspection the ObjectMapper instance in org.junitpioneer.jupiter.json.JacksonJsonConverter
has no registered modules.
Any way to fix this? Or better yet provide a way to customize the used ObjectMapper instance? Right now I’m working around this by using reflection to manually register the module.
Using Gradle 7.1.1 on OpenJDK 11 with classpath.
Issue Analytics
- State:
- Created a year ago
- Comments:16 (12 by maintainers)
Top Results From Across the Web
Can not construct instance of java.time.LocalDate: no String ...
JSON parse error: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String ...
Read more >JSON parse error: Cannot deserialize value of type `java.time ...
In this video, we go through solving this rather annoying Java Jackson Deserialization error : JSON parse error : Cannot deserialize value of ......
Read more >Jackson Exceptions - Problems and Solutions - Baeldung
When we try to deserialize a JSON String to Zoo instance, it throws the JsonMappingException: Can Not Construct Instance Of:
Read more >issues with serialize LocalDate(Time) - Google Groups
throw new IllegalArgumentException("unable to convert json", ex); ... I get the same error for a LocalDate as a LocalDateTime. I haven't tried anything ......
Read more >Jakarta JSON Binding
Implementations SHOULD also report an error during a deserialization operation, if it is not possible to represent a JSON document value ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @virtual-machinist,
thx for reaching out – we will look into this.
For #629 I have some uncommitted changes that register a
Jdk8Module
and aJavaTimeModule
if these are available, and aKotlinModule
if it’s available and so is Kotlin (check on classkotlin.Metadata
). I can create a new PR for that.Maven users indeed would need to add
jackson-datatype-jdk8
andjackson-datatype-jsr310
to their dependencies, but odds are that they already have these as compile or runtime dependencies if they need them in their JSON test definitions, because they most likely need them in their main code as well.