I have a Json response which looks like the following:
{
"data": [
{
"param1": "value1",
"param2": "value2",
.
.
.
"paramN": "valueN"
}
]
}
I don't know the name and the number of the parameters. So, I need and want to bind all these parameters to a java.util.Map field consisting of <"paramX", "valueX"> tuples. To do this, I tried the following code but "parametersMap" field returns null.
@XmlRootElement(name="data")
@XmlAccessorType(XmlAccessType.FIELD)
public class Parameters {
@XmlElement
private Map<String,String> parametersMap;
// Getter and setter for parametersMap
}
How can I achieve such a binding with JAXB annotations?
Thanks in advance.
Basically you need an xml adapter. You can fiddle with the names on the KeyValue class to get the specific output you desire.
Parameter.java
Adapter.java
KeyValue.java Put better JAXB tags here, obviously.