I'm using Retrofit 2 in combination with Gson and RxJava. My JSON data looks something like this:
{
"groups": {
"1": {
"name": "First group",
"type": "some data",
// ... more data
},
"2": {
"name": "Second group",
"type": "some data",
// ... more data
},
"3": {
"name": "Third group",
"type": "some data",
// ... more data
}
// 4, 5, 6, etc...
},
// ... more data
}
In the example above the "keys" 1, 2, 3 are integers but they can also be unique strings. I want to map this JSON data to something like this:
public class MyData {
@SerializedName("groups")
private Map<String, Group> mGroups;
// ... more data
}
public class Group {
// TODO: This should be "1", "2", "3", etc.
@SerializedName(???)
private String mId;
// This should be "First group", "Second group", "Third group", etc.
@SerializedName("name")
private String mName;
// This should be "some data"
@SerializedName("type")
private String mType;
// ... more data
}
What's the best way to put the dynamic key (1, 2, 3) in the Group
object as well? I'm not hosting the JSON data myself so it cannot be changed to another format.