Skip to content

Commit 0afd266

Browse files
author
Lukas Treyer
committed
JSONObject and JSONArray initialization:
JSONObject(Map<String, ?> map) allows to initialize the JSONObject with a Map<String, String> JSONArray(Collection<?> collection) allows to initialize a JSONArray with a Collection<JSONObject>
1 parent b0191a6 commit 0afd266

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

JSONArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ public JSONArray(String source) throws JSONException {
151151
* @param collection
152152
* A Collection.
153153
*/
154-
public JSONArray(Collection<Object> collection) {
154+
public JSONArray(Collection<?> collection) {
155155
this.myArrayList = new ArrayList<Object>();
156156
if (collection != null) {
157-
Iterator<Object> iter = collection.iterator();
157+
Iterator<?> iter = collection.iterator();
158158
while (iter.hasNext()) {
159159
this.myArrayList.add(JSONObject.wrap(iter.next()));
160160
}

JSONObject.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@ public JSONObject(JSONTokener x) throws JSONException {
243243
* the JSONObject.
244244
* @throws JSONException
245245
*/
246-
public JSONObject(Map<String, Object> map) {
246+
public JSONObject(Map<String, ?> map) {
247247
this.map = new HashMap<String, Object>();
248248
if (map != null) {
249-
Iterator<Entry<String, Object>> i = map.entrySet().iterator();
249+
Set<?> eSet = map.entrySet();
250+
@SuppressWarnings("unchecked")
251+
Iterator<Entry<String, ?>> i = (Iterator<Entry<String, ?>>) eSet.iterator();
250252
while (i.hasNext()) {
251-
Entry<String, Object> entry = i.next();
253+
Entry<String, ?> entry = i.next();
252254
Object value = entry.getValue();
253255
if (value != null) {
254256
this.map.put(entry.getKey(), wrap(value));

0 commit comments

Comments
 (0)