Skip to content
Advertisement

Cannot construct instance of `com.domain.User` (no Creators, like default constructor, exist): cannot deserialize from Object value

I have a controller that accepts ObjectNode as @RequestBody.

That ObjectNode represents json with some user data

JavaScript

Controller.java

JavaScript

I want to get user as ObjectNode convert it to Java POJO save it to database and again return it as JsonNode.

UserServiceImpl.java

JavaScript

To convert ObjectNode to POJO

I did this in my UserMapper class:

JavaScript

Also, to write object to JsonNode I did this:

JavaScript

User.java

JavaScript

When I run my application, this is the error I am receiving:

JavaScript

I have read about the error, and it seems this error occurs because Jackson library doesn’t know how to create a model which doesn’t have an empty constructor and the model contains a constructor with parameters which I annotated its parameters with @JsonProperty("fieldName"). But even after applying @JsonProperty("fieldName") I am still getting the same error.

I have defined ObjecatMapper as Bean

JavaScript

What am I missing here?

Advertisement

Answer

I could reproduce the exception. Then I added an all-args constructor with each parameter annotated with the right @JsonProperty.

JavaScript

Now, it creates the instance, but I get other mapping errors (Unrecognized field “given_name”) which you should be able to resolve.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement