I’m parsing JSON using GSON, but get an error when I try to parse JSON containing an empty array.
This is the JSON:
{"Selected":[{"RelatedProducts":[],"ProductReview":null,"ProductId":94}]}
and the error produced:
com.google.gson.JsonParseException: Expecting object found: []
Editing the JSON (a local copy) so that the RelatedProducts array is null instead of [] prevents the error, but I can’t change the JSON being sent from the server.
Is there any way to get GSON to ignore empty arrays (or treat them as null)?
Are you sure that your class that Gson uses to put parsed data into contains an array of objects called RelatedProducts?
Is RelatedProducts an array of objects or just a single object, so to speak?