I am trying to consume an API using Retrofit and Jackson to deserialize. I am getting the onFailure error No Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator
.
Reason:
This error occurs because Jackson Library doesn't know how to create your model which doesn't have an empty constructor and the model contains a constructor with parameters that didn't annotate its parameters with @JsonProperty("field_name")
. By default Java compiler creates an empty constructor if you didn't add a constructor to your class.
Solution:
Add an empty constructor to your model or annotate constructor parameters with @JsonProperty("field_name")
If you use a Kotlin data class then also can annotate with @JsonProperty("field_name")
or register jackson module kotlin to ObjectMapper
.
You can create your models using http://www.jsonschema2pojo.org/.