@Test public void testSaveToDiskSuccess() throws Exception { final Date date = new Date(); final ParseFile file = new ParseFile( new ParseFile.State.Builder().name("image.png").url("http: final ParseGeoPoint geoPoint = new ParseGeoPoint(44.484, 26.029); final List<Object> list = new ArrayList<Object>() {{ add("foo"); add("bar"); add("baz"); }}; final Map<String, Object> map = new HashMap<String, Object>() {{ put("first", "foo"); put("second", "bar"); put("third", "baz"); }}; final Map<String, Object> sampleConfigParameters = new HashMap<String, Object>() {{ put("string", "value"); put("int", 42); put("double", 0.2778); put("trueBool", true); put("falseBool", false); put("date", date); put("file", file); put("geoPoint", geoPoint); put("array", list); put("object", map); }}; JSONObject sampleConfigJson = new JSONObject() {{ put("params", NoObjectsEncoder.get().encode(sampleConfigParameters)); }}; ParseConfig config = ParseConfig.decode(sampleConfigJson, ParseDecoder.get()); File configFile = new File(temporaryFolder.getRoot(), "config"); ParseCurrentConfigController currentConfigController = new ParseCurrentConfigController(configFile); currentConfigController.saveToDisk(config); JSONObject diskConfigJson = new JSONObject(ParseFileUtils.readFileToString(configFile, "UTF-8")); Map<String, Object> decodedDiskConfigObject = (Map<String, Object>) ParseDecoder.get().decode(diskConfigJson); Map<String, Object> decodedDiskConfigParameters = (Map<String, Object>) decodedDiskConfigObject.get("params"); assertEquals(10, decodedDiskConfigParameters.size()); assertEquals("value", decodedDiskConfigParameters.get("string")); assertEquals(42, decodedDiskConfigParameters.get("int")); assertEquals(0.2778, decodedDiskConfigParameters.get("double")); assertTrue((Boolean) decodedDiskConfigParameters.get("trueBool")); assertFalse((Boolean) decodedDiskConfigParameters.get("falseBool")); assertEquals(date, decodedDiskConfigParameters.get("date")); ParseFile fileAgain = (ParseFile) decodedDiskConfigParameters.get("file"); assertEquals(file.getUrl(), fileAgain.getUrl()); assertEquals(file.getName(), fileAgain.getName()); ParseGeoPoint geoPointAgain = (ParseGeoPoint) decodedDiskConfigParameters.get("geoPoint"); assertEquals(geoPoint.getLatitude(), geoPointAgain.getLatitude(), 0.0000001); assertEquals(geoPoint.getLongitude(), geoPointAgain.getLongitude(), 0.0000001); List<Object> listAgain = (List<Object>) decodedDiskConfigParameters.get("array"); assertArrayEquals(list.toArray(), listAgain.toArray()); Map<String, Object> mapAgain = (Map<String, Object>) decodedDiskConfigParameters.get("object"); assertEquals(map.size(), mapAgain.size()); for (Map.Entry<String, Object> entry : map.entrySet()) { assertEquals(entry.getValue(), mapAgain.get(entry.getKey())); } }
void saveToDisk(ParseConfig config) { JSONObject object = new JSONObject(); try { JSONObject jsonParams = (JSONObject) NoObjectsEncoder.get().encode(config.getParams()); object.put("params", jsonParams); } catch (JSONException e) { throw new RuntimeException("could not serialize config to JSON"); } try { ParseFileUtils.writeJSONObjectToFile(currentConfigFile, object); } catch (IOException e) { } }
ParseCurrentConfigController { void saveToDisk(ParseConfig config) { JSONObject object = new JSONObject(); try { JSONObject jsonParams = (JSONObject) NoObjectsEncoder.get().encode(config.getParams()); object.put("params", jsonParams); } catch (JSONException e) { throw new RuntimeException("could not serialize config to JSON"); } try { ParseFileUtils.writeJSONObjectToFile(currentConfigFile, object); } catch (IOException e) { } } }
ParseCurrentConfigController { void saveToDisk(ParseConfig config) { JSONObject object = new JSONObject(); try { JSONObject jsonParams = (JSONObject) NoObjectsEncoder.get().encode(config.getParams()); object.put("params", jsonParams); } catch (JSONException e) { throw new RuntimeException("could not serialize config to JSON"); } try { ParseFileUtils.writeJSONObjectToFile(currentConfigFile, object); } catch (IOException e) { } } ParseCurrentConfigController(File currentConfigFile); }
ParseCurrentConfigController { void saveToDisk(ParseConfig config) { JSONObject object = new JSONObject(); try { JSONObject jsonParams = (JSONObject) NoObjectsEncoder.get().encode(config.getParams()); object.put("params", jsonParams); } catch (JSONException e) { throw new RuntimeException("could not serialize config to JSON"); } try { ParseFileUtils.writeJSONObjectToFile(currentConfigFile, object); } catch (IOException e) { } } ParseCurrentConfigController(File currentConfigFile); Task<Void> setCurrentConfigAsync(final ParseConfig config); Task<ParseConfig> getCurrentConfigAsync(); }
ParseCurrentConfigController { void saveToDisk(ParseConfig config) { JSONObject object = new JSONObject(); try { JSONObject jsonParams = (JSONObject) NoObjectsEncoder.get().encode(config.getParams()); object.put("params", jsonParams); } catch (JSONException e) { throw new RuntimeException("could not serialize config to JSON"); } try { ParseFileUtils.writeJSONObjectToFile(currentConfigFile, object); } catch (IOException e) { } } ParseCurrentConfigController(File currentConfigFile); Task<Void> setCurrentConfigAsync(final ParseConfig config); Task<ParseConfig> getCurrentConfigAsync();  }