Bug 1244944 - Use typed put() variants. r?rnewman
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/ExtendedJSONObject.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/ExtendedJSONObject.java
@@ -1,28 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.sync;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.mozilla.apache.commons.codec.binary.Base64;
import org.mozilla.gecko.sync.UnexpectedJSONException.BadRequiredFieldJSONException;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
/**
* Extend JSONObject to do little things, like, y'know, accessing members.
*
* @author rnewman
*
*/
public class ExtendedJSONObject {
@@ -283,22 +284,46 @@ public class ExtendedJSONObject {
return this.object.toJSONString();
}
@Override
public String toString() {
return this.object.toString();
}
- public void put(String key, Object value) {
+ protected void putRaw(String key, Object value) {
@SuppressWarnings("unchecked")
Map<Object, Object> map = this.object;
map.put(key, value);
}
+ public void put(String key, String value) {
+ this.putRaw(key, value);
+ }
+
+ public void put(String key, boolean value) {
+ this.putRaw(key, value);
+ }
+
+ public void put(String key, long value) {
+ this.putRaw(key, value);
+ }
+
+ public void put(String key, int value) {
+ this.putRaw(key, value);
+ }
+
+ public void put(String key, ExtendedJSONObject value) {
+ this.putRaw(key, value);
+ }
+
+ public void put(String key, JSONArray value) {
+ this.putRaw(key, value);
+ }
+
/**
* Remove key-value pair from JSONObject.
*
* @param key
* to be removed.
* @return true if key exists and was removed, false otherwise.
*/
public boolean remove(String key) {
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java
@@ -60,17 +60,17 @@ public class TestExtendedJSONObject {
}
@Test
public void testSafeInteger() {
ExtendedJSONObject o = new ExtendedJSONObject();
o.put("integer", Integer.valueOf(5));
o.put("string", "66");
o.put("object", new ExtendedJSONObject());
- o.put("null", null);
+ o.put("null", (JSONArray) null);
assertEquals(Integer.valueOf(5), o.getIntegerSafely("integer"));
assertEquals(Integer.valueOf(66), o.getIntegerSafely("string"));
assertNull(o.getIntegerSafely(null));
}
@Test
public void testParseJSONArray() throws Exception {