Cannot deserialize LocalDate in @QueryParam due to missing ParamConverterProvider
See original GitHub issueDescribe the bug
I’m using Jackson (via quarkus-resteasy-jackson) as ObjectMapper
with the KotlinModule
and the JavaTimeModule
registered using an ObjectMapperCustomizer
. When I have an endpoint with a @QueryParam
of type LocalDate
quarkus does not start.
Expected behavior
I expect resteasy to use the provided ObjectMapper
to deserialize a String formated “YYYY-MM-DD” into an instance of LocalDate
.
Actual behavior Omitting the name and method signature for brevity I get
RESTEASY003875: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.QueryParam("adate") for basetype: java.time.LocalDate
To Reproduce Steps to reproduce the behavior:
- Use
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
- Register a resource like
@GET
@Path("path")
fun broken( @QueryParam("adate") aDate: LocalDate) {}
- Run a
@QuarkusTest
to try a start up the application.
Environment (please complete the following information):
- Output of
uname -a
orver
: Linux ninja-cgd 5.3.0-23-generic #25-Ubuntu SMP Tue Nov 12 09:22:33 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux - Output of
java -version
: openjdk version “11.0.5-ea” 2019-10-15 OpenJDK Runtime Environment (build 11.0.5-ea+10-post-Ubuntu-0ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.5-ea+10-post-Ubuntu-0ubuntu1, mixed mode, sharing) - GraalVM version (if different from Java): not used
- Quarkus version or git rev: 0.25.0 Additional context
The problem is fixed by adding
@Provider
class LocalDateConverter : ParamConverterProvider {
override fun <T: Any?> getConverter(rawType: Class<T>?, genericType: Type?, annotations: Array<out Annotation>?): ParamConverter<T>? {
return if (rawType == LocalDate::class.java) {
object: ParamConverter<T> {
val mapper = ObjectMapper().also { JacksonObjectMapperCustomizer().customize(it) }
override fun toString(value: T?): String {
return mapper.writeValueAsString(value)
}
override fun fromString(value: String?): T {
return mapper.readValue(value, LocalDate::class.java) as T
}
}
} else null
}
}
to the project. I was expecting that this kind of Provider would be added out of the box when using Jackson’s JavaTimeModule
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:41 (33 by maintainers)
Top Results From Across the Web
Can not construct instance of java.time.LocalDate: no String ...
You need jackson dependency for this serialization and deserialization. Add this dependency: Gradle:
Read more >Converting JAX-RS parameters with ParamConverters
Here's how to define a converter for LocalDate s. ... ParamConverterProvider; import javax.ws.rs.ext.Provider; import java.lang.annotation.
Read more >mismatchedinputexception: cannot deserialize value of type ...
Jackson deserialization error: MismatchedInputException ... deserialize LocalDate in @QueryParam due to missing ParamConverterProvider#5860.
Read more >Red Hat JBoss Enterprise Application Platform 7.1.0.Beta1
Method that can be called to ask implementation to deserialize JSON content ... from input can not be converted to a non-numeric value...
Read more >Index - Apache TomEE
Exception indicating that the result of a task cannot be retrieved because the task failed to run for some reason other than being...
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 Free
Top 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
@geoand The
"
is part of the JSON.2019-01-01
is invalid; it has to be"2019-01-01"
. See https://www.json.org/json-en.htmlThanks. I’ll take a look tomorrow or Friday