List of usage examples for com.google.gson JsonParser parse
@Deprecated public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException
From source file:com.facebook.ads.sdk.AdCreativeVideoData.java
License:Open Source License
public static APINodeList<AdCreativeVideoData> parseResponse(String json, APIContext context, APIRequest request) throws MalformedResponseException { APINodeList<AdCreativeVideoData> adCreativeVideoDatas = new APINodeList<AdCreativeVideoData>(request, json); JsonArray arr;/* ww w .java 2s . com*/ 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++) { adCreativeVideoDatas.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context)); } ; return adCreativeVideoDatas; } 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; adCreativeVideoDatas.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++) { adCreativeVideoDatas.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()) { adCreativeVideoDatas.add(loadJSON(entry.getValue().toString(), context)); } break; } } if (!isRedownload) { adCreativeVideoDatas.add(loadJSON(obj.toString(), context)); } } return adCreativeVideoDatas; } 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()) { adCreativeVideoDatas.add(loadJSON(entry.getValue().toString(), context)); } return adCreativeVideoDatas; } 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)) { adCreativeVideoDatas.add(loadJSON(value.toString(), context)); } else { isIdIndexedArray = false; break; } } if (isIdIndexedArray) { return adCreativeVideoDatas; } // Sixth, check if it's pure JsonObject adCreativeVideoDatas.clear(); adCreativeVideoDatas.add(loadJSON(json, context)); return adCreativeVideoDatas; } } } catch (Exception e) { exception = e; } throw new MalformedResponseException("Invalid response string: " + json, exception); }
From source file:com.facebook.ads.sdk.AdgroupPlacementSpecificReviewFeedback.java
License:Open Source License
public static AdgroupPlacementSpecificReviewFeedback loadJSON(String json, APIContext context) { AdgroupPlacementSpecificReviewFeedback adgroupPlacementSpecificReviewFeedback = getGson().fromJson(json, AdgroupPlacementSpecificReviewFeedback.class); if (context.isDebug()) { JsonParser parser = new JsonParser(); JsonElement o1 = parser.parse(json); JsonElement o2 = parser.parse(adgroupPlacementSpecificReviewFeedback.toString()); if (o1.getAsJsonObject().get("__fb_trace_id__") != null) { o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__")); }/*from 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); } ; } adgroupPlacementSpecificReviewFeedback.context = context; adgroupPlacementSpecificReviewFeedback.rawValue = json; return adgroupPlacementSpecificReviewFeedback; }
From source file:com.facebook.ads.sdk.AdgroupPlacementSpecificReviewFeedback.java
License:Open Source License
public static APINodeList<AdgroupPlacementSpecificReviewFeedback> parseResponse(String json, APIContext context, APIRequest request) throws MalformedResponseException { APINodeList<AdgroupPlacementSpecificReviewFeedback> adgroupPlacementSpecificReviewFeedbacks = new APINodeList<AdgroupPlacementSpecificReviewFeedback>( request, json);// w ww .ja v a 2s . 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++) { adgroupPlacementSpecificReviewFeedbacks .add(loadJSON(arr.get(i).getAsJsonObject().toString(), context)); } ; return adgroupPlacementSpecificReviewFeedbacks; } 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; adgroupPlacementSpecificReviewFeedbacks.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++) { adgroupPlacementSpecificReviewFeedbacks .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()) { adgroupPlacementSpecificReviewFeedbacks .add(loadJSON(entry.getValue().toString(), context)); } break; } } if (!isRedownload) { adgroupPlacementSpecificReviewFeedbacks.add(loadJSON(obj.toString(), context)); } } return adgroupPlacementSpecificReviewFeedbacks; } 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()) { adgroupPlacementSpecificReviewFeedbacks.add(loadJSON(entry.getValue().toString(), context)); } return adgroupPlacementSpecificReviewFeedbacks; } 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)) { adgroupPlacementSpecificReviewFeedbacks.add(loadJSON(value.toString(), context)); } else { isIdIndexedArray = false; break; } } if (isIdIndexedArray) { return adgroupPlacementSpecificReviewFeedbacks; } // Sixth, check if it's pure JsonObject adgroupPlacementSpecificReviewFeedbacks.clear(); adgroupPlacementSpecificReviewFeedbacks.add(loadJSON(json, context)); return adgroupPlacementSpecificReviewFeedbacks; } } } catch (Exception e) { exception = e; } throw new MalformedResponseException("Invalid response string: " + json, exception); }
From source file:com.facebook.ads.sdk.AdgroupRelevanceScore.java
License:Open Source License
public static AdgroupRelevanceScore loadJSON(String json, APIContext context) { AdgroupRelevanceScore adgroupRelevanceScore = getGson().fromJson(json, AdgroupRelevanceScore.class); if (context.isDebug()) { JsonParser parser = new JsonParser(); JsonElement o1 = parser.parse(json); JsonElement o2 = parser.parse(adgroupRelevanceScore.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 ava2s. c om if (!o1.equals(o2)) { context.log("[Warning] When parsing response, object is not consistent with JSON:"); context.log("[JSON]" + o1); context.log("[Object]" + o2); } ; } adgroupRelevanceScore.context = context; adgroupRelevanceScore.rawValue = json; return adgroupRelevanceScore; }
From source file:com.facebook.ads.sdk.AdgroupRelevanceScore.java
License:Open Source License
public static APINodeList<AdgroupRelevanceScore> parseResponse(String json, APIContext context, APIRequest request) throws MalformedResponseException { APINodeList<AdgroupRelevanceScore> adgroupRelevanceScores = new APINodeList<AdgroupRelevanceScore>(request, json);//from ww w.jav a2 s. c om 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++) { adgroupRelevanceScores.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context)); } ; return adgroupRelevanceScores; } 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; adgroupRelevanceScores.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++) { adgroupRelevanceScores.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()) { adgroupRelevanceScores.add(loadJSON(entry.getValue().toString(), context)); } break; } } if (!isRedownload) { adgroupRelevanceScores.add(loadJSON(obj.toString(), context)); } } return adgroupRelevanceScores; } 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()) { adgroupRelevanceScores.add(loadJSON(entry.getValue().toString(), context)); } return adgroupRelevanceScores; } 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)) { adgroupRelevanceScores.add(loadJSON(value.toString(), context)); } else { isIdIndexedArray = false; break; } } if (isIdIndexedArray) { return adgroupRelevanceScores; } // Sixth, check if it's pure JsonObject adgroupRelevanceScores.clear(); adgroupRelevanceScores.add(loadJSON(json, context)); return adgroupRelevanceScores; } } } catch (Exception e) { exception = e; } throw new MalformedResponseException("Invalid response string: " + json, exception); }
From source file:com.facebook.ads.sdk.AdgroupReviewFeedback.java
License:Open Source License
public static AdgroupReviewFeedback loadJSON(String json, APIContext context) { AdgroupReviewFeedback adgroupReviewFeedback = getGson().fromJson(json, AdgroupReviewFeedback.class); if (context.isDebug()) { JsonParser parser = new JsonParser(); JsonElement o1 = parser.parse(json); JsonElement o2 = parser.parse(adgroupReviewFeedback.toString()); if (o1.getAsJsonObject().get("__fb_trace_id__") != null) { o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__")); }//from w ww. j a v a 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); } ; } adgroupReviewFeedback.context = context; adgroupReviewFeedback.rawValue = json; return adgroupReviewFeedback; }
From source file:com.facebook.ads.sdk.AdgroupReviewFeedback.java
License:Open Source License
public static APINodeList<AdgroupReviewFeedback> parseResponse(String json, APIContext context, APIRequest request) throws MalformedResponseException { APINodeList<AdgroupReviewFeedback> adgroupReviewFeedbacks = new APINodeList<AdgroupReviewFeedback>(request, json);/*w w w .j ava 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++) { adgroupReviewFeedbacks.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context)); } ; return adgroupReviewFeedbacks; } 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; adgroupReviewFeedbacks.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++) { adgroupReviewFeedbacks.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()) { adgroupReviewFeedbacks.add(loadJSON(entry.getValue().toString(), context)); } break; } } if (!isRedownload) { adgroupReviewFeedbacks.add(loadJSON(obj.toString(), context)); } } return adgroupReviewFeedbacks; } 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()) { adgroupReviewFeedbacks.add(loadJSON(entry.getValue().toString(), context)); } return adgroupReviewFeedbacks; } 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)) { adgroupReviewFeedbacks.add(loadJSON(value.toString(), context)); } else { isIdIndexedArray = false; break; } } if (isIdIndexedArray) { return adgroupReviewFeedbacks; } // Sixth, check if it's pure JsonObject adgroupReviewFeedbacks.clear(); adgroupReviewFeedbacks.add(loadJSON(json, context)); return adgroupReviewFeedbacks; } } } catch (Exception e) { exception = e; } throw new MalformedResponseException("Invalid response string: " + json, exception); }
From source file:com.facebook.ads.sdk.AdImage.java
License:Open Source License
public static AdImage loadJSON(String json, APIContext context) { AdImage adImage = getGson().fromJson(json, AdImage.class); if (context.isDebug()) { JsonParser parser = new JsonParser(); JsonElement o1 = parser.parse(json); JsonElement o2 = parser.parse(adImage.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 v a2 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); } ; } adImage.context = context; adImage.rawValue = json; return adImage; }
From source file:com.facebook.ads.sdk.AdImage.java
License:Open Source License
public static APINodeList<AdImage> parseResponse(String json, APIContext context, APIRequest request) throws MalformedResponseException { APINodeList<AdImage> adImages = new APINodeList<AdImage>(request, json); JsonArray arr;//w ww. jav a 2 s . c o 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++) { adImages.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context)); } ; return adImages; } 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; adImages.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++) { adImages.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()) { adImages.add(loadJSON(entry.getValue().toString(), context)); } break; } } if (!isRedownload) { adImages.add(loadJSON(obj.toString(), context)); } } return adImages; } 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()) { adImages.add(loadJSON(entry.getValue().toString(), context)); } return adImages; } 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)) { adImages.add(loadJSON(value.toString(), context)); } else { isIdIndexedArray = false; break; } } if (isIdIndexedArray) { return adImages; } // Sixth, check if it's pure JsonObject adImages.clear(); adImages.add(loadJSON(json, context)); return adImages; } } } catch (Exception e) { exception = e; } throw new MalformedResponseException("Invalid response string: " + json, exception); }
From source file:com.facebook.ads.sdk.AdKeywordStats.java
License:Open Source License
public static AdKeywordStats loadJSON(String json, APIContext context) { AdKeywordStats adKeywordStats = getGson().fromJson(json, AdKeywordStats.class); if (context.isDebug()) { JsonParser parser = new JsonParser(); JsonElement o1 = parser.parse(json); JsonElement o2 = parser.parse(adKeywordStats.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 .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); } ; } adKeywordStats.context = context; adKeywordStats.rawValue = json; return adKeywordStats; }