I have to map a JSON to Java PoJos using JAX-RS (Resteasy as implementation). The problem is, that the JSON is dynamic. Look at this example:
{
"typeCode": "SAMPLE",
"data": [
{
"id": "COMMENTS",
"answerValue": {
"type": "YesNoAnswer",
"value": true
}
},
{
"id": "CHOICE",
"answerValue": {
"type": "SelectListAnswer",
"values": ["choice1", "choice2"]
}
}
]
}
The dynamic elements are in the data array. In principal every entry has an ID and an answerValue. But the answerValue is dynamic. Depending on his type he can have a single value (boolean, string, number an object) or an array of values.
How can I map this to my Java model?