I have a JSON of structure
{
"name": "...",
"age": "..."
}
I have to map this JSON to following class object
Class Response {
Person person;
}
Class Person {
String name;
String age;
}
Is there any Jackson annotation that helps me do this without changing the JSON structure or modifying the class structure?
Just add
@JsonUnrapped
annotation overPerson person;
in yourResponse
class. And by the way, classes in Java are defined by class not Class. Doesn't your code fails to compile? And you should add getters/setters to your classes if you haven't done alreadyResponse class:
Person class:
And here is a small test code to verify it: