beta.blog

Programming

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.package.dtos.TestDTO` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)

by on Feb.25, 2019, under Programming

Ever received an exception reading the text below?

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.package.dtos.TestDTO (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)

The exception simply occurred because the DTO (data transfer object) you’re trying to map to doesn’t contain a default constructor. In fact, a zero args constructor is required.

Before:

public class TestDTO {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

After:

public class TestDTO {
    private String name;

    public TestDTO() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Or in case your using Lombok in order to reduce boilerplate code:

Before:

@Data
@AllArgsConstructor
public class TestDTO {
    private String name;
}

After:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TestDTO {
    private String name;
}

It’s that easy.

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!