Merge pull request #907 from hexetia/fix-901

Fix a bug when calling JSONArray.addAll() with Collection as Object
This commit is contained in:
Sean Leary 2024-11-13 16:29:34 -06:00 committed by GitHub
commit 2ee5bf13f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -1939,7 +1939,7 @@ public class JSONArray implements Iterable<Object> {
// JSONArray
this.myArrayList.addAll(((JSONArray)array).myArrayList);
} else if (array instanceof Collection) {
this.addAll((Collection<?>)array, wrap, recursionDepth);
this.addAll((Collection<?>)array, wrap, recursionDepth, jsonParserConfiguration);
} else if (array instanceof Iterable) {
this.addAll((Iterable<?>)array, wrap);
} else {

View File

@ -259,6 +259,11 @@ public class JSONArrayTest {
jsonArray.length(),
len);
// collection as object
@SuppressWarnings("RedundantCast")
Object myListAsObject = (Object) myList;
jsonArray.putAll(myListAsObject);
for (int i = 0; i < myList.size(); i++) {
assertEquals("collection elements should be equal",
myList.get(i),