cannot deserialize from Object value (no delegate- or property-based Creator) even with default constructor present

We Are Going To Discuss About cannot deserialize from Object value (no delegate- or property-based Creator) even with default constructor present. So lets Start this Java Article.

cannot deserialize from Object value (no delegate- or property-based Creator) even with default constructor present

  1. cannot deserialize from Object value (no delegate- or property-based Creator) even with default constructor present

    EDIT:
    I just found a much better solution, add the ParanamerModule to the ObjectMapper:
    mapper.registerModule(new ParanamerModule());
    Maven:
    <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-paranamer</artifactId> <version>${jackson.version}</version> </dependency>

  2. cannot deserialize from Object value (no delegate- or property-based Creator) even with default constructor present

    EDIT:
    I just found a much better solution, add the ParanamerModule to the ObjectMapper:
    mapper.registerModule(new ParanamerModule());
    Maven:
    <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-paranamer</artifactId> <version>${jackson.version}</version> </dependency>

Solution 1

EDIT:

I just found a much better solution, add the ParanamerModule to the ObjectMapper:

mapper.registerModule(new ParanamerModule());

Maven:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-paranamer</artifactId>
    <version>${jackson.version}</version>
</dependency>

The advantage against the ParameterNamesModule seems to be that the classes do not need to be compiled with the -parameters argument.

END EDIT


With Jackson 2.9.9 I tried to deserialize this simple POJO and came accros the same exception, adding a default constructor solved the problem:

POJO:

public class Operator {

    private String operator;

    public Operator(String operator) {
        this.operator = operator;
    }

    public String getOperator() {
        return operator;
    }
}

ObjectMapper and Serialize/Deserialize:

ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.ANY);

String value = mapper.writeValueAsString(new Operator("test"));
Operator result = mapper.readValue(value, Operator.class);

JSON:

{"operator":"test"}

Exception:

com.fasterxml.jackson.databind.exc.MismatchedInputException: 
Cannot construct instance of `...Operator` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (String)"{"operator":"test"}"; line: 1, column: 2]

Solution (POJO with default constructor):

public class Operator {

    private String operator;

    private Operator() {
    }

    public Operator(String operator) {
        this();
        this.operator = operator;
    }

    public String getOperator() {
        return operator;
    }
}

Original Author flavio.donze Of This Content

Solution 2

I observed this same issue. My issue was caused by me using the wrong JsonCreator type. I incorrectly used org.codehaus.jackson.annotate.JsonCreator, but should have used com.fasterxml.jackson.annotation.JsonCreator instead.

Original Author Andreas Presthammer Of This Content

Solution 3

In your subclass object add default constructor:

public NameOfClass() {
    super();
}

Original Author atreyHazelHispanic Of This Content

Solution 4

I got this error and I tried https://newbedev.com/no-creators-like-default-construct-exist-cannot-deserialize-from-object-value-no-delegate-or-property-based-creator

Basically added

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)

decorators and it worked for me.

Original Author coda Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment