Permalink
Browse files

Fix for JSONArray with Collection instead of Array (see also http://c…

  • Loading branch information...
1 parent 9be3701 commit 46f1e189894ec2e70c0107449d4b58aa839c0d15 @vorburger committed Jun 21, 2012
Showing with 6 additions and 2 deletions.
  1. +1 −1 pom.xml
  2. +5 −1 src/main/java/org/json/JSONArray.java
View
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
- <version>20100401-NING-3.0.2-SNAPSHOT</version>
+ <version>20100401-NING-3.0.3-SNAPSHOT</version>
<name>JSON (JavaScript Object Notation)</name>
<description>
@@ -192,13 +192,17 @@ public JSONArray(Object array) throws JSONException {
*/
public JSONArray(Object array, boolean includeSuperClass) throws JSONException {
this();
+ if (array instanceof Collection) {
+ Collection<?> collection = (Collection<?>) array;
+ array = collection.toArray();
+ }
if (array.getClass().isArray()) {
int length = Array.getLength(array);
for (int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i), includeSuperClass));
}
} else {
- throw new JSONException("JSONArray initial value should be a string or collection or array.");
+ throw new JSONException("JSONArray initial value should be a string or collection or array instead of " + array.getClass());
}
}

0 comments on commit 46f1e18

Please sign in to comment.