Example usage for com.google.gson JsonParser parse

List of usage examples for com.google.gson JsonParser parse

Introduction

In this page you can find the example usage for com.google.gson JsonParser parse.

Prototype

@Deprecated
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException 

Source Link

Usage

From source file:com.facebook.ads.sdk.ProductCatalogHotelRoomsBatch.java

License:Open Source License

public static ProductCatalogHotelRoomsBatch loadJSON(String json, APIContext context) {
    ProductCatalogHotelRoomsBatch productCatalogHotelRoomsBatch = getGson().fromJson(json,
            ProductCatalogHotelRoomsBatch.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(productCatalogHotelRoomsBatch.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }/* w  w w . j  av a 2s .com*/
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    productCatalogHotelRoomsBatch.context = context;
    productCatalogHotelRoomsBatch.rawValue = json;
    return productCatalogHotelRoomsBatch;
}

From source file:com.facebook.ads.sdk.ProductCatalogHotelRoomsBatch.java

License:Open Source License

public static APINodeList<ProductCatalogHotelRoomsBatch> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<ProductCatalogHotelRoomsBatch> productCatalogHotelRoomsBatchs = new APINodeList<ProductCatalogHotelRoomsBatch>(
            request, json);//from   w  w w  .j a v a 2s.co m
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                productCatalogHotelRoomsBatchs.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return productCatalogHotelRoomsBatchs;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    productCatalogHotelRoomsBatchs.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        productCatalogHotelRoomsBatchs
                                .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                productCatalogHotelRoomsBatchs
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        productCatalogHotelRoomsBatchs.add(loadJSON(obj.toString(), context));
                    }
                }
                return productCatalogHotelRoomsBatchs;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    productCatalogHotelRoomsBatchs.add(loadJSON(entry.getValue().toString(), context));
                }
                return productCatalogHotelRoomsBatchs;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        productCatalogHotelRoomsBatchs.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return productCatalogHotelRoomsBatchs;
                }

                // Sixth, check if it's pure JsonObject
                productCatalogHotelRoomsBatchs.clear();
                productCatalogHotelRoomsBatchs.add(loadJSON(json, context));
                return productCatalogHotelRoomsBatchs;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.ProductCatalogImageSettings.java

License:Open Source License

public static ProductCatalogImageSettings loadJSON(String json, APIContext context) {
    ProductCatalogImageSettings productCatalogImageSettings = getGson().fromJson(json,
            ProductCatalogImageSettings.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(productCatalogImageSettings.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }/* w  w w . j  a va2 s  .c  o m*/
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    productCatalogImageSettings.context = context;
    productCatalogImageSettings.rawValue = json;
    return productCatalogImageSettings;
}

From source file:com.facebook.ads.sdk.ProductCatalogImageSettings.java

License:Open Source License

public static APINodeList<ProductCatalogImageSettings> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<ProductCatalogImageSettings> productCatalogImageSettingss = new APINodeList<ProductCatalogImageSettings>(
            request, json);// w ww. j a va  2  s. com
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                productCatalogImageSettingss.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return productCatalogImageSettingss;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    productCatalogImageSettingss.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        productCatalogImageSettingss
                                .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                productCatalogImageSettingss
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        productCatalogImageSettingss.add(loadJSON(obj.toString(), context));
                    }
                }
                return productCatalogImageSettingss;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    productCatalogImageSettingss.add(loadJSON(entry.getValue().toString(), context));
                }
                return productCatalogImageSettingss;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        productCatalogImageSettingss.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return productCatalogImageSettingss;
                }

                // Sixth, check if it's pure JsonObject
                productCatalogImageSettingss.clear();
                productCatalogImageSettingss.add(loadJSON(json, context));
                return productCatalogImageSettingss;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.ProductCatalogImageSettingsOperation.java

License:Open Source License

public static ProductCatalogImageSettingsOperation loadJSON(String json, APIContext context) {
    ProductCatalogImageSettingsOperation productCatalogImageSettingsOperation = getGson().fromJson(json,
            ProductCatalogImageSettingsOperation.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(productCatalogImageSettingsOperation.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//from w  ww. java 2  s.  co  m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    productCatalogImageSettingsOperation.context = context;
    productCatalogImageSettingsOperation.rawValue = json;
    return productCatalogImageSettingsOperation;
}

From source file:com.facebook.ads.sdk.ProductCatalogImageSettingsOperation.java

License:Open Source License

public static APINodeList<ProductCatalogImageSettingsOperation> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<ProductCatalogImageSettingsOperation> productCatalogImageSettingsOperations = new APINodeList<ProductCatalogImageSettingsOperation>(
            request, json);//from www  . j  a  v a 2 s  . co  m
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                productCatalogImageSettingsOperations
                        .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return productCatalogImageSettingsOperations;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    productCatalogImageSettingsOperations.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        productCatalogImageSettingsOperations
                                .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                productCatalogImageSettingsOperations
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        productCatalogImageSettingsOperations.add(loadJSON(obj.toString(), context));
                    }
                }
                return productCatalogImageSettingsOperations;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    productCatalogImageSettingsOperations.add(loadJSON(entry.getValue().toString(), context));
                }
                return productCatalogImageSettingsOperations;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        productCatalogImageSettingsOperations.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return productCatalogImageSettingsOperations;
                }

                // Sixth, check if it's pure JsonObject
                productCatalogImageSettingsOperations.clear();
                productCatalogImageSettingsOperations.add(loadJSON(json, context));
                return productCatalogImageSettingsOperations;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.ProductCatalogPricingVariablesBatch.java

License:Open Source License

public static ProductCatalogPricingVariablesBatch loadJSON(String json, APIContext context) {
    ProductCatalogPricingVariablesBatch productCatalogPricingVariablesBatch = getGson().fromJson(json,
            ProductCatalogPricingVariablesBatch.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(productCatalogPricingVariablesBatch.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//from   ww w. j a va 2 s  .  co  m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    productCatalogPricingVariablesBatch.context = context;
    productCatalogPricingVariablesBatch.rawValue = json;
    return productCatalogPricingVariablesBatch;
}

From source file:com.facebook.ads.sdk.ProductCatalogPricingVariablesBatch.java

License:Open Source License

public static APINodeList<ProductCatalogPricingVariablesBatch> parseResponse(String json, APIContext context,
        APIRequest request) throws MalformedResponseException {
    APINodeList<ProductCatalogPricingVariablesBatch> productCatalogPricingVariablesBatchs = new APINodeList<ProductCatalogPricingVariablesBatch>(
            request, json);/*w ww  .  j  av  a2 s .c  o m*/
    JsonArray arr;
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                productCatalogPricingVariablesBatchs
                        .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return productCatalogPricingVariablesBatchs;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    productCatalogPricingVariablesBatchs.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        productCatalogPricingVariablesBatchs
                                .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                productCatalogPricingVariablesBatchs
                                        .add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        productCatalogPricingVariablesBatchs.add(loadJSON(obj.toString(), context));
                    }
                }
                return productCatalogPricingVariablesBatchs;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    productCatalogPricingVariablesBatchs.add(loadJSON(entry.getValue().toString(), context));
                }
                return productCatalogPricingVariablesBatchs;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        productCatalogPricingVariablesBatchs.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return productCatalogPricingVariablesBatchs;
                }

                // Sixth, check if it's pure JsonObject
                productCatalogPricingVariablesBatchs.clear();
                productCatalogPricingVariablesBatchs.add(loadJSON(json, context));
                return productCatalogPricingVariablesBatchs;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}

From source file:com.facebook.ads.sdk.ProductFeed.java

License:Open Source License

public static ProductFeed loadJSON(String json, APIContext context) {
    ProductFeed productFeed = getGson().fromJson(json, ProductFeed.class);
    if (context.isDebug()) {
        JsonParser parser = new JsonParser();
        JsonElement o1 = parser.parse(json);
        JsonElement o2 = parser.parse(productFeed.toString());
        if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
            o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
        }//from  ww w .j  ava 2 s  . co  m
        if (!o1.equals(o2)) {
            context.log("[Warning] When parsing response, object is not consistent with JSON:");
            context.log("[JSON]" + o1);
            context.log("[Object]" + o2);
        }
        ;
    }
    productFeed.context = context;
    productFeed.rawValue = json;
    return productFeed;
}

From source file:com.facebook.ads.sdk.ProductFeed.java

License:Open Source License

public static APINodeList<ProductFeed> parseResponse(String json, APIContext context, APIRequest request)
        throws MalformedResponseException {
    APINodeList<ProductFeed> productFeeds = new APINodeList<ProductFeed>(request, json);
    JsonArray arr;/*from  w  ww  . j a  v a 2s  .  co m*/
    JsonObject obj;
    JsonParser parser = new JsonParser();
    Exception exception = null;
    try {
        JsonElement result = parser.parse(json);
        if (result.isJsonArray()) {
            // First, check if it's a pure JSON Array
            arr = result.getAsJsonArray();
            for (int i = 0; i < arr.size(); i++) {
                productFeeds.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
            }
            ;
            return productFeeds;
        } else if (result.isJsonObject()) {
            obj = result.getAsJsonObject();
            if (obj.has("data")) {
                if (obj.has("paging")) {
                    JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
                    String before = paging.has("before") ? paging.get("before").getAsString() : null;
                    String after = paging.has("after") ? paging.get("after").getAsString() : null;
                    productFeeds.setPaging(before, after);
                }
                if (obj.get("data").isJsonArray()) {
                    // Second, check if it's a JSON array with "data"
                    arr = obj.get("data").getAsJsonArray();
                    for (int i = 0; i < arr.size(); i++) {
                        productFeeds.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context));
                    }
                    ;
                } else if (obj.get("data").isJsonObject()) {
                    // Third, check if it's a JSON object with "data"
                    obj = obj.get("data").getAsJsonObject();
                    boolean isRedownload = false;
                    for (String s : new String[] { "campaigns", "adsets", "ads" }) {
                        if (obj.has(s)) {
                            isRedownload = true;
                            obj = obj.getAsJsonObject(s);
                            for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                                productFeeds.add(loadJSON(entry.getValue().toString(), context));
                            }
                            break;
                        }
                    }
                    if (!isRedownload) {
                        productFeeds.add(loadJSON(obj.toString(), context));
                    }
                }
                return productFeeds;
            } else if (obj.has("images")) {
                // Fourth, check if it's a map of image objects
                obj = obj.get("images").getAsJsonObject();
                for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
                    productFeeds.add(loadJSON(entry.getValue().toString(), context));
                }
                return productFeeds;
            } else {
                // Fifth, check if it's an array of objects indexed by id
                boolean isIdIndexedArray = true;
                for (Map.Entry entry : obj.entrySet()) {
                    String key = (String) entry.getKey();
                    if (key.equals("__fb_trace_id__")) {
                        continue;
                    }
                    JsonElement value = (JsonElement) entry.getValue();
                    if (value != null && value.isJsonObject() && value.getAsJsonObject().has("id")
                            && value.getAsJsonObject().get("id") != null
                            && value.getAsJsonObject().get("id").getAsString().equals(key)) {
                        productFeeds.add(loadJSON(value.toString(), context));
                    } else {
                        isIdIndexedArray = false;
                        break;
                    }
                }
                if (isIdIndexedArray) {
                    return productFeeds;
                }

                // Sixth, check if it's pure JsonObject
                productFeeds.clear();
                productFeeds.add(loadJSON(json, context));
                return productFeeds;
            }
        }
    } catch (Exception e) {
        exception = e;
    }
    throw new MalformedResponseException("Invalid response string: " + json, exception);
}