1
1
package com .contentstack .sdk ;
2
2
3
- import java .util .ArrayList ;
4
- import java .util .LinkedHashMap ;
5
- import java .util .List ;
6
3
import org .jetbrains .annotations .NotNull ;
7
4
import org .json .JSONArray ;
8
5
import org .json .JSONObject ;
6
+
7
+ import java .util .ArrayList ;
8
+ import java .util .LinkedHashMap ;
9
+ import java .util .List ;
10
+ import java .util .Map ;
9
11
import java .util .logging .Logger ;
10
12
11
13
@@ -68,6 +70,7 @@ protected synchronized void setJSON(@NotNull JSONObject jsonobject) {
68
70
69
71
if (receiveJson .has ("items" )) {
70
72
Object itemsObj = receiveJson .opt ("items" );
73
+
71
74
if (itemsObj instanceof JSONArray ) {
72
75
JSONArray jsonArray = (JSONArray ) itemsObj ;
73
76
syncItems = new ArrayList <>();
@@ -77,14 +80,26 @@ protected synchronized void setJSON(@NotNull JSONObject jsonobject) {
77
80
syncItems .add (sanitizeJson (jsonItem ));
78
81
}
79
82
}
80
- } else {
81
- if (itemsObj instanceof JSONObject ) {
82
- syncItems = new ArrayList <>();
83
- syncItems .add (sanitizeJson ((JSONObject ) itemsObj ));
84
- } else {
85
- logger .warning ("'items' is not a valid list. Skipping processing." );
86
- syncItems = new ArrayList <>();
83
+ } else if (itemsObj instanceof JSONObject ) {
84
+ syncItems = new ArrayList <>();
85
+ syncItems .add (sanitizeJson ((JSONObject ) itemsObj ));
86
+ } else if (itemsObj instanceof List ) {
87
+ List <?> itemsList = (List <?>) itemsObj ;
88
+ syncItems = new ArrayList <>();
89
+ for (Object item : itemsList ) {
90
+ if (item instanceof JSONObject ) {
91
+ syncItems .add (sanitizeJson ((JSONObject ) item ));
92
+ } else if (item instanceof Map ) {
93
+ JSONObject jsonItem = new JSONObject ((Map <?, ?>) item );
94
+ syncItems .add (sanitizeJson (jsonItem ));
95
+ } else {
96
+ logger .warning ("Item in ArrayList is not a JSONObject or LinkedHashMap. Skipping. Type: " + item .getClass ().getName ());
97
+ }
87
98
}
99
+ } else {
100
+ logger .warning ("'items' is not a valid JSONArray, JSONObject, or ArrayList. Type: " +
101
+ (itemsObj != null ? itemsObj .getClass ().getName () : "null" ));
102
+ syncItems = new ArrayList <>();
88
103
}
89
104
} else {
90
105
syncItems = new ArrayList <>();
0 commit comments