question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON argument source fails with LocalDate property deserialization

See original GitHub issue

For 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:open
  • Created a year ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
beatngu13commented, Apr 20, 2022

Hi @virtual-machinist,

thx for reaching out – we will look into this.

0reactions
robtimuscommented, May 21, 2022

For #629 I have some uncommitted changes that register a Jdk8Module and a JavaTimeModule if these are available, and a KotlinModule if it’s available and so is Kotlin (check on class kotlin.Metadata). I can create a new PR for that.

Maven users indeed would need to add jackson-datatype-jdk8 and jackson-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found