I have probably easy question to advanced json/gson users. I get on request something like below:
[{
"1": {
"2": "6+"
}
},{
"1": []
}]
I try deserialize it to java object using gson but I meet problems. Gson reports to me :
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line X column Y
As I see the problem is that in first item '1' value is declared as an object and in second as and array. I don't have influence on generated JSON. Any idea how map it properly?
Maybe in gson I can add some hook and during parsing have influence what should be done with items? E.g. when for item "1" value is "[]" then do something different than when object with values is given?
After Arkain comment i must add:
- In presented example still we have the same object - but it is presented differently :/ (once as empty array - other time as object)
From analysis I think that Object should be represented as e.g.
public class Example { Map<String, Object> 1 = new Map<String,Object>; ... }
but i don't know why when map is empty is represented in JSON as an empty array.
- I don't know amount of positions and type of particular position in JSON collection.