public static JSONArray removeNamespacesFromOGJsonArray( JSONArray jsonArray, boolean requireNamespace) throws JSONException { JSONArray newArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); ++i) { Object value = jsonArray.get(i); if (value instanceof JSONArray) { value = removeNamespacesFromOGJsonArray((JSONArray) value, requireNamespace); } else if (value instanceof JSONObject) { value = removeNamespacesFromOGJsonObject((JSONObject) value, requireNamespace); } newArray.put(value); } return newArray; }
value = jsonObject.get(key); if (value instanceof JSONObject) { value = removeNamespacesFromOGJsonObject((JSONObject) value, true); } else if (value instanceof JSONArray) { value = removeNamespacesFromOGJsonArray((JSONArray) value, true);
@Test public void testRemoveNamespaceFromNullOGJsonObject() { assertNull(ShareInternalUtility.removeNamespacesFromOGJsonObject(null, false)); }
public static Bundle create(ShareOpenGraphContent shareOpenGraphContent) { Bundle params = createBaseParameters(shareOpenGraphContent); Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_TYPE, shareOpenGraphContent.getAction().getActionType()); try { JSONObject ogJSON = ShareInternalUtility.toJSONObjectForWeb(shareOpenGraphContent); ogJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(ogJSON, false); if (ogJSON != null) { Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_PROPERTIES, ogJSON.toString()); } } catch (JSONException e) { throw new FacebookException("Unable to serialize the ShareOpenGraphContent to JSON", e); } return params; }
@Test public void testRemoveNamespaceFromComplexOGJsonObject() { try { JSONObject testObject = getJsonOGActionTestObject(); testObject = ShareInternalUtility.removeNamespacesFromOGJsonObject(testObject, false); JSONObject expectedResult = getJsonOGActionTestObjectWithoutNamespace(); if(!simpleJsonObjComparer(testObject, expectedResult)){ fail(String.format( Locale.ROOT, "Actual: %s\nExpected: %s", testObject.toString(), expectedResult.toString())); } } catch (JSONException ex) { // Fail assertNotNull(ex); } }
JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, openGraphContent); openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject( openGraphActionJSON, false); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);