I\'m trying to deserialize a JSONArray with Gson, one the values\' type can vary, the value \"in_wanted\" can be either a boolean or a JSONOb
You could do a manual parsing, something like:
JsonParser parser = new JsonParser();
JsonObject rootObject = parser.parse(yourJsonString).getAsJsonObject();
JsonObject movieObject = rootObject
.getAsJsonArray("movies")
.get(0).getAsJsonObject();
JsonElement inWantedElement = movieObject.get("in_wanted");
//Check if "in_wanted" element is a boolean or an object
if (inWantedElement.isJsonObject()) {
//Process the element as an object...
//for example get the element "value"...
boolean value = inWantedElement
.getAsJsonObject()
.getAsJsonObject("profile")
.getAsJsonPrimitive("value")
.getAsBoolean();
}
else if (inWantedElement.isJsonPrimitive()) {
//Process the element as a boolean...
boolean inWanted = inWantedElement.getAsBoolean();
}
Note: see Gson API documentation for further info about types JsonObject, JsonArray, JsonElement, and so on...