Say I have the following class:
public class Parent {
public int age;
@JsonUnwrapped
public Name name;
}
Producing JSON:
You can use @JsonCreator with @JsonProperty for each field:
@JsonCreator
public Parent(@JsonProperty("age") Integer age, @JsonProperty("firstName") String firstName,
@JsonProperty("lastName") String lastName) {
this.age = age;
this.name = new Name(firstName, lastName);
}
Jackson does type checking and unknown field checking for you in this case.