I have 2 classes as such
class Parent {
private final Optional<Child> child;
@JsonCreator
Parent(@JsonProperty("child") Optional<Child> child) {
this.child = child;
}
}
class Child {
private final Optional<String> name;
@JsonCreator
Child(@JsonProperty("name")Optional<String> name){
this.name = name;
}
}
The json that I intend to deserialize into the Parent class looks like below:
{
"child" : {
"name" : "abc"
}
}
To deserialize itself I am using the ObjectMapper:
ObjectMapper mapper = new ObjectMapper()
.registerModule(new Jdk8Module());
However at runtime getting the exception below:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.util.Optional` (no Creators, like default constructor, exist): cannot deserialize from Object value
A lot of answer on stack suggest the use of registerModule like this one. Am I missing something in the use of registerModule?