1

I use the openapi generator kotlin module to generate kotlin classes from my openapi.yaml file. The process works fine until I try to deserialize the received JSON in my code to a kotlin class using Jackson.

This is the generated class

data class Request (
    @field:JsonProperty("name")
    var name: kotlin.String,
)

This is the error I get

java.lang.IllegalArgumentException: Cannot construct instance of `...package.Request` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: UNKNOWN; byte offset: #UNKNOWN]

I noticed that when I remove the "@field:" part in the generated code, then everything works like a charm.

So now my question is can I either remove the @field from the generator or make Jackson deserialize it correctly?

The versions that I use are

  • jackson: 2.13.1
  • open-api-generator (gradle plugin): 5.3.0
Jonathan R
  • 3,652
  • 3
  • 22
  • 40
  • Does this answer your question? [Usage of Jackson @JsonProperty annotation for kotlin data classes](https://stackoverflow.com/questions/47982148/usage-of-jackson-jsonproperty-annotation-for-kotlin-data-classes) – Karsten Gabriel Mar 22 '22 at 19:09

1 Answers1

1

I had the same error and registering the Kotlin Jackson module fixed it for me: https://github.com/FasterXML/jackson-module-kotlin

Malthor
  • 11
  • 1