I am using Gson to parse JSON (generated by the jquery query builder) to a corresponding Java Object. My issue is that the attribute "value" can be either an array or a single value:
{
"condition": "AND",
"rules": [
{
"id": "date",
"field": "date",
"type": "date",
"input": "text",
"operator": "between",
"value": [
"01.01.2016",
"20.01.2016"
]
}
]
}
or
{
"condition": "AND",
"rules": [
{
"id": "date",
"field": "date",
"type": "date",
"input": "text",
"operator": "equal",
"value": "01.01.2016"
}
]
}
Apparently Gson can build the object for the first JSON if my class has a field like private String[] value
and for the second, a field like private String value
— but not both JSON inputs with either Java field option.
So my question: Is the a way to handle both, either a single "value" or an array of "values"?