I am receiving the following json from an external rest call.
{
// other keys coming in too, but already mapped
"someData": {
"someContent": {
"item1": "",
"otherItem25": "",
"anotherData34": ""
}
}
}
I wish to map it to an object.
I could do the following which works.
Solution 1
private Map<String, Map<String, String>> someData;
But looking to map it to named objects.
Like following which works too.
Solution 2
class Root {
private someData someData;
}
class SomeData {
private SomeContent someContent;
}
class SomeContent {
@JsonProperty("item1")
private String one;
@JsonProperty("otherItem25")
private String two;
@JsonProperty("anotherData34")
private String three;
}
The issue is with the last bit where I am individually naming the Strings. I don't want to do that cos this is meant to grow and I could land with about 50 Strings soon. I don't want to create 50 Strings.
Other than the above 2 solutions, is there a better way to map this json to an Object?
Something like this would have been ideal but won't work cos there is nothing to identify as nnerData in the json.
class SomeContent {
private Map<String, String> innerData;
}
Please advice.
P.S: I can't modify the json