ConfigMapper { public static ReadableMap toMap(Config config) { WritableMap out = Arguments.createMap(); WritableMap httpHeaders = Arguments.createMap(); if (config.getStationaryRadius() != null) { out.putDouble("stationaryRadius", config.getStationaryRadius()); } if (config.getDistanceFilter() != null) { out.putInt("distanceFilter", config.getDistanceFilter()); } if (config.getDesiredAccuracy() != null) { out.putInt("desiredAccuracy", config.getDesiredAccuracy()); } if (config.isDebugging() != null) { out.putBoolean("debug", config.isDebugging()); } if (config.getNotificationTitle() != null) { if (config.getNotificationTitle() != Config.NullString) { out.putString("notificationTitle", config.getNotificationTitle()); } else { out.putNull("notificationTitle"); } } if (config.getNotificationText() != null) { if (config.getNotificationText() != Config.NullString) { out.putString("notificationText", config.getNotificationText()); } else { out.putNull("notificationText"); } } if (config.getLargeNotificationIcon() != null) { if (config.getLargeNotificationIcon() != Config.NullString) { out.putString("notificationIconLarge", config.getLargeNotificationIcon()); } else { out.putNull("notificationIconLarge"); } } if (config.getSmallNotificationIcon() != null) { if (config.getSmallNotificationIcon() != Config.NullString) { out.putString("notificationIconSmall", config.getSmallNotificationIcon()); } else { out.putNull("notificationIconSmall"); } } if (config.getNotificationIconColor() != null) { if (config.getNotificationIconColor() != Config.NullString) { out.putString("notificationIconColor", config.getNotificationIconColor()); } else { out.putNull("notificationIconColor"); } } if (config.getStopOnTerminate() != null) { out.putBoolean("stopOnTerminate", config.getStopOnTerminate()); } if (config.getStartOnBoot() != null) { out.putBoolean("startOnBoot", config.getStartOnBoot()); } if (config.getStartForeground() != null) { out.putBoolean("startForeground", config.getStartForeground()); } if (config.getNotificationsEnabled() != null) { out.putBoolean("notificationsEnabled", config.getNotificationsEnabled()); } if (config.getLocationProvider() != null) { out.putInt("locationProvider", config.getLocationProvider()); } if (config.getInterval() != null) { out.putInt("interval", config.getInterval()); } if (config.getFastestInterval() != null) { out.putInt("fastestInterval", config.getFastestInterval()); } if (config.getActivitiesInterval() != null) { out.putInt("activitiesInterval", config.getActivitiesInterval()); } if (config.getStopOnStillActivity() != null) { out.putBoolean("stopOnStillActivity", config.getStopOnStillActivity()); } if (config.getUrl() != null) { if (config.getUrl() != Config.NullString) { out.putString("url", config.getUrl()); } else { out.putNull("url"); } } if (config.getSyncUrl() != null) { if (config.getSyncUrl() != Config.NullString) { out.putString("syncUrl", config.getSyncUrl()); } else { out.putNull("syncUrl"); } } if (config.getSyncThreshold() != null) { out.putInt("syncThreshold", config.getSyncThreshold()); } Iterator<Map.Entry<String, String>> it = config.getHttpHeaders().entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pair = it.next(); httpHeaders.putString(pair.getKey(), pair.getValue()); } out.putMap("httpHeaders", httpHeaders); if (config.getMaxLocations() != null) { out.putInt("maxLocations", config.getMaxLocations()); } LocationTemplate tpl = config.getTemplate(); if (tpl instanceof HashMapLocationTemplate) { Map map = ((HashMapLocationTemplate)tpl).toMap(); if (map != null) { out.putMap("postTemplate", MapUtil.toWritableMap(map)); } else { out.putNull("postTemplate"); } } else if (tpl instanceof ArrayListLocationTemplate) { Object[] keys = ((ArrayListLocationTemplate)tpl).toArray(); if (keys != null) { out.putArray("postTemplate", ArrayUtil.toWritableArray(keys)); } else { out.putNull("postTemplate"); } } return out; }  static Config fromMap(ReadableMap options); static ReadableMap toMap(Config config);  }
@Test @Ignore public void testDefaultToJSONObject() { Config config = Config.getDefault(); ReadableMap map = ConfigMapper.toMap(config); Assert.assertEquals(config.getStationaryRadius(), map.getDouble("stationaryRadius"), 0f); Assert.assertEquals(config.getDistanceFilter().intValue(), map.getInt("distanceFilter")); Assert.assertEquals(config.getDesiredAccuracy().intValue(), map.getInt("desiredAccuracy")); Assert.assertEquals(config.isDebugging().booleanValue(), map.getBoolean("debug")); Assert.assertEquals(config.getNotificationTitle(), map.getString("notificationTitle")); Assert.assertEquals(config.getNotificationText(), map.getString("notificationText")); Assert.assertEquals(config.getStopOnTerminate().booleanValue(), map.getBoolean("stopOnTerminate")); Assert.assertEquals(config.getStartOnBoot().booleanValue(), map.getBoolean("startOnBoot")); Assert.assertEquals(config.getLocationProvider().intValue(), map.getInt("locationProvider")); Assert.assertEquals(config.getInterval().intValue(), map.getInt("interval")); Assert.assertEquals(config.getFastestInterval().intValue(), map.getInt("fastestInterval")); Assert.assertEquals(config.getActivitiesInterval().intValue(), map.getInt("activitiesInterval")); Assert.assertEquals(config.getNotificationIconColor(), map.getString("notificationIconColor")); Assert.assertEquals(config.getLargeNotificationIcon(), map.getString("notificationIconLarge")); Assert.assertEquals(config.getSmallNotificationIcon(), map.getString("notificationIconSmall")); Assert.assertEquals(config.getStartForeground().booleanValue(), map.getBoolean("startForeground")); Assert.assertEquals(config.getStopOnStillActivity().booleanValue(), map.getBoolean("stopOnStillActivity")); Assert.assertEquals(config.getUrl(), map.getString("url")); Assert.assertEquals(config.getSyncUrl(), map.getString("syncUrl")); Assert.assertEquals(config.getSyncThreshold().intValue(), map.getInt("syncThreshold")); Assert.assertEquals(config.getMaxLocations().intValue(), map.getInt("maxLocations")); }