Let's assume there are those 2 different json structures - both contain the same values, but the key hierarchy differs - one is flat, the other is nested:
- Flat:
{
"documentId": "7ef1229c-301a-40d9-8c0c-faf5da54785d",
"first_name": "Xbyvuve",
"last_name": "Abmhlakwd"
}
- Nested:
{
"_meta": {
"_more_nested" {
"documentId": "7ef1229c-301a-40d9-8c0c-faf5da54785d",
}
},
"first_name": "Xbyvuve",
"last_name": "Abmhlakwd"
}
Resulting in Object:
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class PersonDocument {
String documentId;
String firstName;
String lastName;
}
Is there a way in Jackson to instantiate the same object from both json strings without providing a custom deserializer? For instance with a special annotation? In addition, I also want the resulting json string on serialization to be like the "flat" json string.
Thank you in advance!
Tried different annotations without any positive result :<