I recently stumbled on an issue with parsing mapping values which are handed over via a List.
I receive a Json and within the JSON there is an extra field attributes. Which looks like this
"attributes": [
{
"id": "id",
"value": "12345677890124566"
},
{
"id": "Criticality",
"value": "medium"
},
{
"id": "type",
"value": "business"
},
{
"id": "active",
"value": "true"
}
],
I fetch it via parsing it into a List via (List<Map<String, String>>) request.get("attributes")
attributes.
I parse through the list via : for (Map<String, String> attribute : attributes)
.
I am not able to get the value of any attribute. I tried stuff like get("active")
, containsKey
and much more the only result I get is null
.
I tried parsing the value from the mapping for an attribute but received only null
instead of the value.
2
Answers
you try to access to map data with
get("active")
but you should use
get("value")
i hope this example can help :
You attributes data is not a map in the Java sense. It is an array of objects each with an id and a value.
This will work: