I have a map property:
private Map<String, Attribute> attributes = new HashMap<>();
Attribute
object looks like this:
public class Attribute{
private String value;
private String name;
//with constructor setters and getters
}
How do I represent attributes Map
object as JSON?
I am getting a JsonSyntaxException
:
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY
when I'm trying to convert JSON object using fromJson()
in the following code:
Attribute attribute = Gson().fromJson(jsonObect,Attribute.class)
My JSON object looks like this:
{
"attributes":[
{
"name":"some name",
"value":"some value"
}
]
}