Question
How to Fix Jackson "No Creators, like default construct, exist" Error in Java Retrofit Deserialization
Question
I am consuming an API in a Java application using Retrofit and Jackson for JSON deserialization. During the request, Retrofit triggers onFailure with this Jackson error:
No Creators, like default construct, exist: cannot deserialize from Object value (no delegate- or property-based Creator)
Why does this happen, and how can I fix my model class so Jackson can deserialize the API response correctly?
Short Answer
By the end of this page, you will understand what Jackson means by a Creator, why Retrofit surfaces this error during deserialization, and how to fix your Java model classes using a no-argument constructor, @JsonCreator, and @JsonProperty when needed.
Concept
Jackson converts JSON into Java objects by creating an instance of your class and then filling in its fields or calling its constructor parameters.
That error means Jackson received a JSON object like this:
{
"id": 1,
"name": "Alice"
}
but it could not figure out how to create the Java object first.
In Jackson, a Creator is a way to build an object during deserialization. Common options are:
- a public no-argument constructor
- a constructor annotated with
@JsonCreator - constructor parameters annotated with
@JsonProperty - a builder pattern configured for Jackson
If your class only has a constructor with parameters and no default constructor, Jackson often cannot instantiate it automatically unless you explicitly tell it how.
This matters in real programming because API clients depend on reliable mapping between JSON responses and Java classes. If your models are not deserialization-friendly, network calls may succeed but object mapping will fail.
Mental Model
Think of Jackson as a delivery worker bringing JSON data to your Java class.
- The JSON is the package.
- Your Java class is the apartment.
- Jackson must first get inside the apartment before placing the items.
If the apartment has an unlocked front door, that is like a no-argument constructor.
If the apartment requires a special entry code, that is like a constructor with parameters. Jackson needs clear instructions about which values go where. Those instructions are provided with @JsonCreator and @JsonProperty.
Without a door or instructions, Jackson stands outside and throws the "No Creators" error.
Syntax and Examples
Basic fix: add a no-argument constructor
If your class uses mutable fields or setters, the simplest fix is often to add a default constructor.
public class User {
private int id;
private String name;
public User() {
// Default constructor required by Jackson
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Jackson can now:
- call
new User() - set
id - set
name
Alternative fix: use
Step by Step Execution
Consider this JSON response:
{
"id": 10,
"name": "Maya"
}
And this Java class:
public class User {
private int id;
private String name;
public User() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
What Jackson does:
Real World Use Cases
This issue appears often in API-driven Java applications.
Mobile or Android apps using Retrofit
A request succeeds, but parsing fails because the response model has only custom constructors.
Backend services consuming other APIs
A service calls an external API and maps the result into DTOs. If the DTOs are immutable but not annotated correctly, deserialization breaks.
JSON config loading
Applications often load JSON configuration into Java objects. Jackson still needs a valid way to create each object.
Data transfer objects in layered apps
Controllers, services, and clients often use DTO classes. These classes must be designed with serialization and deserialization in mind.
Real Codebase Usage
In real projects, developers usually choose one of these patterns:
1. Mutable DTOs with no-arg constructors
Common in simple apps and generated models.
public class ProductDto {
private String sku;
private double price;
public ProductDto() {}
public String getSku() { return sku; }
public void setSku(String sku) { this.sku = sku; }
public double getPrice() { return price; }
public void setPrice(double price) { this.price = price; }
}
2. Immutable DTOs with @JsonCreator
Common when developers want safer objects.
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
{
String sku;
price;
{
.sku = sku;
.price = price;
}
String { sku; }
{ price; }
}
Common Mistakes
1. Only defining a parameterized constructor
This is the most common cause.
Broken
public class User {
private int id;
private String name;
public User(int id, String name) {
this.id = id;
this.name = name;
}
}
Fix
- add a no-argument constructor, or
- annotate the constructor with
@JsonCreatorand@JsonProperty
2. Missing getters and setters for mutable classes
If Jackson relies on setters and they do not exist, field population may fail.
public class User {
private int id;
}
Safer version:
public class User {
private int id;
{}
{
id;
}
{
.id = id;
}
}
Comparisons
| Approach | How Jackson creates object | Best for | Pros | Cons |
|---|---|---|---|---|
| No-arg constructor + setters | Create empty object, then set fields | Simple DTOs | Easy to understand | Mutable objects |
@JsonCreator + @JsonProperty | Call constructor with JSON values | Immutable DTOs | Clear mapping, safer objects | More verbose |
| Public fields | Direct field access | Quick prototypes | Minimal code | Less encapsulation |
| Builder pattern | Use configured builder | Complex objects | Flexible for large models | More setup |
Cheat Sheet
// Option 1: mutable class
public class User {
private int id;
private String name;
public User() {}
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
// Option 2: immutable class
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class User {
private final int id;
private final String name;
@JsonCreator
{
.id = id;
.name = name;
}
{ id; }
String { name; }
}
FAQ
Why does Jackson say "No Creators"?
Jackson cannot find a valid way to create an instance of your class during deserialization.
Do I always need a default constructor?
No. You can also use a constructor annotated with @JsonCreator and parameter names annotated with @JsonProperty.
Why does this happen in Retrofit onFailure?
Retrofit uses Jackson to parse the response. If parsing fails, the call may end up in the failure path depending on your adapter and converter setup.
Can private fields still be deserialized?
Yes, often they can, especially with getters/setters or Jackson configuration. But the object still needs a valid creation method.
What if my JSON field names are different from my Java fields?
Use @JsonProperty("json_name") to map them correctly.
Does this error mean the API response is invalid?
Not always. The JSON may be perfectly valid, but your Java class may not be compatible with Jackson deserialization.
Should I use mutable or immutable DTOs?
Both are valid. Mutable DTOs are simpler for beginners. Immutable DTOs are safer and often preferred in larger codebases.
Mini Project
Description
Create a small Java model for an API response representing a book. The purpose is to practice building a Jackson-friendly class that Retrofit can deserialize without throwing the "No Creators" error.
Goal
Build a response model that correctly deserializes JSON for a book object using constructor-based mapping.
Requirements
- Create a
Bookclass withid,title, andauthorfields. - Make the fields immutable using
final. - Use Jackson annotations so the class can be deserialized from JSON.
- Add getter methods for each field.
- Test it against a JSON object with matching keys.
Keep learning
Related questions
Android AlarmManager Example: Scheduling Tasks with AlarmManager
Learn how to use Android AlarmManager to schedule tasks, set alarms, and handle broadcasts with a simple beginner example.
Can You Extend a Data Class in Kotlin? Inheritance, Limits, and Better Alternatives
Learn why Kotlin data classes cannot be extended, what causes the component function clash, and which alternatives to use instead.
Difference Between List and Array in Kotlin
Learn the difference between List and Array in Kotlin, including mutability, size, APIs, performance, and when to use each one.