I have a POJO that holds another POJO:
public class Outer {
private Long id;
private String name;
@JsonUnwrapped
private Inner inner;
}
And this is the Inner class:
public class Inner {
private Long id;
private String name;
private String feature;
}
As you can see both these objects may have id and name, so as whereas I used @JsonUnwrapped, there might be some duplicated keys.
I have a rest controller:
@RestController
public class Temp {
@RequestMapping("/test")
public Outer test() {
Inner inner = new Inner(null, "innerName", "feature");
Outer outer = new Outer(10L, "outerName", inner);
return outer;
}
}
Whenever I call the method, the result would be like this:
{"id":1, name:"outerName", id: null, name:"innerName","feature":"feature"}
I want to get this result:
{"id":1, name:"innerName","feature":"feature"}
I mean whenever the inner object has a value for the duplicate key, the value should be picked up from the inner object and if the value was null for the duplicate key inside the inner class, the value should be picked up from the outer object.