Resolving Jackson Deserialization Creator Exception
Jackson is commonly used in Java applications to convert JSON into Java objects. This process is called deserialization. A common exception during deserialization is: Cannot deserialize from Object value (no delegate- or property-based Creator). This exception occurs when Jackson receives a JSON object but cannot figure out how to create an instance of the target Java class. For example, given this JSON:
{
"name": "John",
"age": 30
}
Jackson needs a way to create a User object and populate its values. If the class has neither a usable default constructor nor a constructor that Jackson can use as a property-based creator, the deserialization fails.
1. Reproducing the Deserialization Exception
Jackson needs a way to create a Java object before it can populate its properties from JSON. By default, it looks for a no-argument constructor or an explicitly defined creator that tells it how to map JSON properties to constructor parameters. Consider a User class that only has a parameterized constructor:
public User(String name, int age) {
this.name = name;
this.age = age;
}
Now suppose Jackson needs to deserialize the following JSON:
{
"name": "John",
"age": 30
}
Jackson cannot use the parameterized constructor automatically because it does not know that name and age should be mapped to its parameters. Since there is also no default constructor, Jackson has no suitable way to create the User object and throws:
Cannot deserialize from Object value (no delegate- or property-based Creator)
The exception therefore indicates that Jackson could not find a suitable constructor or creator for the target class.
2. Resolving the Issue with a Default Constructor
The simplest way to resolve the exception is to provide a no-argument constructor. This gives Jackson a way to create the object before populating its properties from the JSON. Jackson then follows a simple two-step process:
- Create the object using the default constructor.
- Populate the object’s properties from the JSON.
For a mutable Java bean, this usually means providing a default constructor along with setters for the properties that Jackson needs to populate.
3. Using a Property-Based Creator
Another approach is to explicitly tell Jackson which constructor to use when creating the object. This is useful when the class does not have a default constructor, especially for immutable classes. Jackson provides @JsonCreator to identify the constructor, while @JsonProperty maps each constructor parameter to its corresponding JSON property.
@JsonCreator
public User(
@JsonProperty("name") String name,
@JsonProperty("age") int age) {
this.name = name;
this.age = age;
}
Jackson can now read the name and age properties from the JSON and pass them directly to the constructor. The object is therefore created in a single step. This approach is particularly useful for immutable classes where fields are declared final and setters are intentionally avoided.
4. Resolving Constructor Parameter Name Mapping
When using constructor-based deserialization, Jackson needs to know which JSON property corresponds to each constructor parameter. The most straightforward approach is to explicitly use @JsonProperty:
@JsonProperty("name") String name
@JsonProperty("age") int age
Another option is to compile the Java application with the -parameters compiler option. This preserves constructor parameter names in the compiled bytecode, allowing frameworks such as Jackson to discover them at runtime. For Maven, this can be enabled with:
<parameters>true</parameters>
Without this metadata, Java reflection may expose constructor parameters as arg0, arg1, and so on instead of their actual names. This is why explicitly specifying @JsonProperty is often the clearest and most reliable approach when defining a Jackson creator.
5. Complete Java Example
The following example demonstrates the complete problem and its solution. It uses a single User class and shows both approaches: a default constructor and a property-based creator.
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Main {
public static class User {
private final String name;
private final int age;
/*
* Default constructor.
* Jackson can use this constructor when deserializing
* into a mutable object.
*/
public User() {
this.name = null;
this.age = 0;
}
/*
* Property-based creator.
* Jackson can use this constructor to create an
* immutable User directly from JSON properties.
*/
@JsonCreator
public User(
@JsonProperty("name") String name,
@JsonProperty("age") int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
public static void main(String[] args) throws Exception {
String json = ""
" {
"name": "John",
"age": 30
}
""
";
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(json, User.class);
System.out.println("Name: " + user.getName());
System.out.println("Age: " + user.getAge());
}
}
5.1 Code Explanation
The example defines a User class with two final fields, name and age. The class provides both a default constructor and a property-based constructor. The default constructor gives Jackson a way to create the object without arguments, while the @JsonCreator constructor explicitly tells Jackson to create the object using the name and age values from the JSON. The @JsonProperty annotations map each JSON property to the corresponding constructor parameter. In the main() method, the JSON string contains a user named John with an age of 30. An ObjectMapper is then used with readValue() to deserialize the JSON into a User object. Finally, the getter methods are used to print the deserialized values.
5.2 Code Output
After successful deserialization, the User object contains the values provided in the JSON. The getter methods return these values, which are then printed to the console.
Name: John Age: 30
6. Conclusion
The exception Cannot deserialize from Object value (no delegate- or property-based Creator) occurs when Jackson cannot determine how to construct the target Java object. The issue can usually be resolved by either adding a default constructor, allowing Jackson to create and populate the object, or by defining a property-based creator using @JsonCreator and @JsonProperty. The property-based approach is particularly useful for immutable classes because all required values can be provided when the object is created. Using @JsonProperty also makes the mapping between JSON properties and constructor parameters explicit, avoiding dependency on compiler-retained parameter names.

