I have a JSON data which looks like this:
{
"status": "status",
"date": "01/10/2019",
"time": "10:30 AM",
"labels": {
"field1": "value1",
"field2": "value2",
...
"field100": "value100"
}
"description": "some description"
}
In my Java code, I have two classes:
Alertsclass which has the following fields - status, date, time, description andLabelsclass.The inner
Labelsclass which is supposed to hold all the fields fromfield1throughfield100(and more)
I'm parsing this JSON into GSON like this:
Alerts myAlert = gson.fromJson(alertJSON, Alert.class);
The above code parses the JSON into the Alert object and the Labels object.
Question:
Instead of mapping the fields (field1, field2, etc) inside Labels object as individual String fields, how can I parse them into a map?
For example, the Labels object would look like this:
public class Labels {
// I want to parse all the fields (field1, field2, etc) into
// this map
Map<String, String> fields = new HashMap<>();
}
How do I do this?