NCMBObject extends NCMBBase { public void addToList(String key, List objects) throws NCMBException { if (getObjectId() != null && !mFields.isNull(key)){ if (isIgnoreKey(key)) { throw new NCMBException(NCMBException.INVALID_FORMAT, "Can't put data to same name with property key."); } else { try { JSONObject addOperation = new JSONObject("{\"__op\":\"Add\"}"); String listJsonStr = new Gson().toJson(objects); addOperation.put("objects", new JSONArray(listJsonStr)); mFields.put(key, addOperation); mUpdateKeys.add(key); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid JSON data"); } } } } NCMBObject(String className);   NCMBObject(String className, JSONObject params); void save(); void saveInBackground(final DoneCallback callback); void fetch(); void fetchInBackground(); void fetchInBackground(final FetchCallback callback); void deleteObject(); void deleteObjectInBackground(final DoneCallback callback); void increment(String key, int amount); void addToList(String key, List objects); void addUniqueToList(String key, List objects); void removeFromList(String key, List objects);  }
@Test public void add_operation() throws Exception { NCMBObject obj = new NCMBObject("testClass", new JSONObject("{\"list\":[\"value1\",\"value2\"]}")); obj.setObjectId("testObjectId"); obj.addToList("list", Arrays.asList("value1", "value2")); JSONAssert.assertEquals(new JSONObject("{\"__op\":\"Add\",\"objects\":[\"value1\",\"value2\"]}"), obj.mFields.getJSONObject("list"), true); }