I have come across an API that returns different types of value for "fieldValue" as follow:
{
"id" : 123,
"fieldType" : "text",
"fieldValue" : "some test"
}
{
"id" : 456,
"fieldType" : "checkbox",
"fieldValue" :
[
{
"checkboxId" : 1,
"name" : "Homer"
},
{
"checkboxId" : 2,
"name" : "Marge"
}
]
}
{
"id" : 789,
"fieldType" : "Select",
"fieldValue" : {
"selectId" : 3,
"value" : "Lisa"
}
}
I am using GSON and it doesn't like that the fact that "fieldValue" can be either String or an object or an array. I have written custom deserializer to parse it. My question is that does JSON specification allow JSON object to have loosely defined value type meaning fieldValue type can be either String, Array of objects or an object?