Skip to content
JSON Tidy
JSON errors

Cannot construct instance (no Creators, like default constructor, exist)

Updated by John Marshall

To turn JSON into an object, Jackson first has to create the object. By default it calls a no-argument constructor and then sets each field. If your class doesn’t have one, and no constructor is marked for Jackson to use, it stops with this error before reading a single field. The same message, with a different ending, appears when the type is an interface, or when the JSON has a string where an object should be.

Quick fix

  1. Read the end of the message to see which case you have. The table below lists each one.
  2. For a class without a no-argument constructor, add one, or mark your constructor with @JsonCreator and name each argument with @JsonProperty.
  3. If the message ends with from String value, look at the JSON: an object was probably sent as a string.

An example

This class is immutable, so its only constructor takes every field:

public class User {
    private final String name;
    private final int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

User user = mapper.readValue("{\"name\": \"Maya\", \"age\": 34}", User.class);
Cannot construct instance of `com.example.User` (no Creators, like default constructor, exist):
cannot deserialize from Object value (no delegate- or property-based Creator)

Jackson can see the constructor, but Java doesn’t keep parameter names at runtime unless you ask it to, so Jackson has no way to know that the first argument is name. “Creator” is Jackson’s word for a constructor or factory method it’s allowed to use.

What each version means

Every version starts with Cannot construct instance of and the class name. The end of the message tells you why:

(no Creators, like default constructor, exist): cannot deserialize from Object valueThe class has no no-argument constructor, and no constructor Jackson knows how to use. Fix
(although at least one Creator exists): cannot deserialize from Object valueThe class has a one-argument constructor, and Jackson can’t tell whether that argument is the name field or the whole object. Fix
(no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types…You asked for an interface or abstract class, which can’t be created. Fix
: non-static inner classes like this can only by instantiated using default, no-argument constructorThe class is declared inside another class without static. Fix
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String valueThe JSON has a string where an object or list should be. Fix

Classes without a no-argument constructor

The quickest fix is to add an empty constructor, and setters or non-final fields for Jackson to fill. If you’d rather keep the class immutable, tell Jackson to use the constructor you have, and which JSON field goes to each argument:

public class User {
    private final String name;
    private final int age;

    @JsonCreator
    public User(@JsonProperty("name") String name, @JsonProperty("age") int age) {
        this.name = name;
        this.age = age;
    }
}

This also fixes the “although at least one Creator exists” version, which you get with a one-argument constructor. Without the annotations, Jackson can’t tell whether new User(String name) should get the name field or the whole JSON value.

If you’re on Java 16 or later, a record does the same with no annotations. Jackson 2.12 and later read records through their canonical constructor:

public record User(String name, int age) {}

Lombok. @Value and @Builder classes have no no-argument constructor, so they fail the same way. Add @Jacksonized next to @Builder, and Jackson builds the object through the builder:

@Value
@Builder
@Jacksonized
public class User {
    String name;
    int age;
}

Kotlin. Data classes usually have no no-argument constructor either. Register the Kotlin module (jacksonObjectMapper() does it for you), which reads constructor parameter names from Kotlin’s metadata.

Interfaces and abstract classes

Jackson can’t create an interface, so it needs to know which class to use. If there’s only one, ask for that class directly. If the JSON can hold several kinds, a field like "type" usually says which. Tell Jackson to read it:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
    @JsonSubTypes.Type(value = Card.class, name = "card"),
    @JsonSubTypes.Type(value = PayPal.class, name = "paypal")
})
public interface Payment {}

// {"type": "card", "last4": "4242"} is read as a Card

Inner classes

A class declared inside another class without static needs an instance of the outer class to exist, which Jackson doesn’t have. This often happens with a class written inside a test. Add static to the class declaration, or move it to its own file.

A string where an object should be

This version is about the JSON, not your class:

Cannot construct instance of `com.example.Address` (although at least one Creator exists):
no String-argument constructor/factory method to deserialize from String value ('{"city": "Boston"}')
 (through reference chain: com.example.Customer["address"])

The message quotes the string it found, and here the string is itself JSON. The address was converted to JSON twice, so the response looks like this:

{"name": "Maya", "address": "{\"city\": \"Boston\"}"}

That usually happens when a server calls JSON.stringify or json.dumps on a value that’s already a JSON string, or stores JSON in a text column and sends it as is. The best fix is in that code. If you can’t change it, make the field a String and parse it with a second mapper.readValue call. To see the inner JSON, paste the string into the unescape tool.

The same message appears for a list field that gets a single value, like "tags": "api" instead of ["api"]. Annotate the field with @JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) to accept both. For values with the wrong shape in general, see Cannot deserialize value of type.

The same error elsewhere

Jackson 2Cannot construct instance of `com.example.User` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
Spring MVCJSON parse error: Cannot construct instance of `com.example.User` (no Creators, like default constructor, exist)
C#, System.Text.JsonDeserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'MyApp.User'.
C#, interfacesDeserialization of interface or abstract types is not supported. Type 'MyApp.IPayment'.