mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
changed all method signatures containing collections and maps to accept
wildcard generic types, e.g. Collection<?> instead of Collection<Object>. This was proposed by other pull requests (#111, #112) already. Consider this commit as merge with #111 and #112. JSONArray: - put(Collection<?> value) {...} - put(Map<String, ?> value) {...} - put(int index, Collection<?> value) throws JSONException {...} - put(int index, Map<String, ?> value) throws JSONException {...} JSONObject: - put(String key, Collection<?> value) throws JSONException {...} - put(String key, Map<String, ?> value) throws JSONException {...} Changed all code affected by new JSONObject and JSONArray constructors: JSONObject: - valueToString(Object value) throws JSONException { - value instanceof Map - value instanceof Collection } - wrap(Object object) { - value instanceof Map - value instanceof Collection } - writeValue(Writer writer, Object value, int indentFactor, int indent){ - value instanceof Map - value instanceof Collection }
This commit is contained in:
parent
0afd26623c
commit
409eb9f292
2 changed files with 13 additions and 14 deletions
|
@ -746,7 +746,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* A Collection value.
|
* A Collection value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(Collection<Object> value) {
|
public JSONArray put(Collection<?> value) {
|
||||||
this.put(new JSONArray(value));
|
this.put(new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -799,7 +799,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* A Map value.
|
* A Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(Map<String, Object> value) {
|
public JSONArray put(Map<String, ?> value) {
|
||||||
this.put(new JSONObject(value));
|
this.put(new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -848,7 +848,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
* If the index is negative or if the value is not finite.
|
* If the index is negative or if the value is not finite.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(int index, Collection<Object> value) throws JSONException {
|
public JSONArray put(int index, Collection<?> value) throws JSONException {
|
||||||
this.put(index, new JSONArray(value));
|
this.put(index, new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +920,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* If the index is negative or if the the value is an invalid
|
* If the index is negative or if the the value is an invalid
|
||||||
* number.
|
* number.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(int index, Map<String, Object> value) throws JSONException {
|
public JSONArray put(int index, Map<String, ?> value) throws JSONException {
|
||||||
this.put(index, new JSONObject(value));
|
this.put(index, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1206,7 +1206,7 @@ public class JSONObject {
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject put(String key, Collection<Object> value) throws JSONException {
|
public JSONObject put(String key, Collection<?> value) throws JSONException {
|
||||||
this.put(key, new JSONArray(value));
|
this.put(key, new JSONArray(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1270,7 +1270,7 @@ public class JSONObject {
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject put(String key, Map<String, Object> value) throws JSONException {
|
public JSONObject put(String key, Map<String, ?> value) throws JSONException {
|
||||||
this.put(key, new JSONObject(value));
|
this.put(key, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1666,12 +1666,12 @@ public class JSONObject {
|
||||||
}
|
}
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> map = (Map<String, Object>) value;
|
Map<String, ?> map = (Map<String, ?>) value;
|
||||||
return new JSONObject(map).toString();
|
return new JSONObject(map).toString();
|
||||||
}
|
}
|
||||||
if (value instanceof Collection) {
|
if (value instanceof Collection) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Collection<Object> coll = (Collection<Object>) value;
|
Collection<?> coll = (Collection<?>) value;
|
||||||
return new JSONArray(coll).toString();
|
return new JSONArray(coll).toString();
|
||||||
}
|
}
|
||||||
if (value.getClass().isArray()) {
|
if (value.getClass().isArray()) {
|
||||||
|
@ -1710,7 +1710,7 @@ public class JSONObject {
|
||||||
|
|
||||||
if (object instanceof Collection) {
|
if (object instanceof Collection) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Collection<Object> coll = (Collection<Object>) object;
|
Collection<?> coll = (Collection<?>) object;
|
||||||
return new JSONArray(coll);
|
return new JSONArray(coll);
|
||||||
}
|
}
|
||||||
if (object.getClass().isArray()) {
|
if (object.getClass().isArray()) {
|
||||||
|
@ -1718,7 +1718,7 @@ public class JSONObject {
|
||||||
}
|
}
|
||||||
if (object instanceof Map) {
|
if (object instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> map = (Map<String, Object>) object;
|
Map<String, ?> map = (Map<String, ?>) object;
|
||||||
return new JSONObject(map);
|
return new JSONObject(map);
|
||||||
}
|
}
|
||||||
Package objectPackage = object.getClass().getPackage();
|
Package objectPackage = object.getClass().getPackage();
|
||||||
|
@ -1758,13 +1758,12 @@ public class JSONObject {
|
||||||
((JSONArray) value).write(writer, indentFactor, indent);
|
((JSONArray) value).write(writer, indentFactor, indent);
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> map = (Map<String, Object>) value;
|
Map<String, ?> map = (Map<String, ?>) value;
|
||||||
new JSONObject(map).write(writer, indentFactor, indent);
|
new JSONObject(map).write(writer, indentFactor, indent);
|
||||||
} else if (value instanceof Collection) {
|
} else if (value instanceof Collection) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Collection<Object> coll = (Collection<Object>) value;
|
Collection<?> coll = (Collection<?>) value;
|
||||||
new JSONArray(coll).write(writer, indentFactor,
|
new JSONArray(coll).write(writer, indentFactor, indent);
|
||||||
indent);
|
|
||||||
} else if (value.getClass().isArray()) {
|
} else if (value.getClass().isArray()) {
|
||||||
new JSONArray(value).write(writer, indentFactor, indent);
|
new JSONArray(value).write(writer, indentFactor, indent);
|
||||||
} else if (value instanceof Number) {
|
} else if (value instanceof Number) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue