I'd like to register the Kotlin-Module with Jackson in a Quarkus application so Jackson can deserialize JSON into data classes without needing a NoArgsConstructor. What is the best way to do this?
Update after comment
The application is a REST service written in Kotlin. At the API level we use View classes (e.g. PersonView or PersonWriteView) to abstract from the models and entities on the service resp. persistence layer. To reduce overhead while still getting nice and meaningful equals() and hashcode() functions we use data class
es for this.
In the vanilla settings Jackson is not able to directly deserialize into data classes because it needs an empty constructor. This can be monkey patched by applying the no-arg compiler plugin and add an annotation e.g. @NoArgConstructor
similar to what Lombok offers. But of course this way we have to annotate each data class in the API which is error prone.
A better solution for this is to include com.fasterxml.jackson.module:jackson-module-kotlin which gets you the marvelous KotlinModule. After this mapper.treeToValue()
can directly create data class
instances without the need for an empty constructor.
For this to work we have to register the module with the ObjectMapper e.g. via ObjectMapper().findAndRegisterModules()
. All I want to know is how to configure the ObjectMapper which is used by Resteasy to unmarshal the JSON to objects.