Jackson/Kotlin: No Creators, like default construct, exist — deserialization error
Hello everyone! I'm new to Kotlin and trying to use Retrofit + Jackson for parsing JSON in Android. I have a simple data class:
```kotlin
data class User(
val id: Int,
val name: String,
val email: String
)
```
And a Retrofit interface:
```kotlin
interface ApiService {
@GET("users/{id}")
suspend fun getUser(@Path("id") id: Int): User
}
```
But when I try to execute the request, I get an exception:
```
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.example.app.User` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (BufferedInputStream); line: 1, column: 2]
```
I'm using Jackson via the `jackson-module-kotlin` module. What's the problem? I defined a data class with all fields using val, why can't Jackson create an object? I tried adding @JsonProperty — it didn't help. Please advise how to configure correctly.
No answers yet.
Log in to leave an answer