88 * JSON object, String, Number (BigDecimal), Boolean, null, Object[] array of listed types;
99 * - JSON object members (name/value pairs) are stored in creation/appearance order;
1010 * - when the names within an object are not unique, parser stores the last value only;
11+ * - JSON object setter accepts any Java object, all Java primitives and primitive arrays;
12+ * - in addition to the parsed types, the generator converts Java Lists, Sets to JSON arrays
13+ * and Java Maps to JSON objects. The null key is converted to a "null" member name.
14+ * Other Java objects are converted to JSON strings.
1115 *
1216 * Created: 2020-03-07
1317 */
1620import java .io .IOException ;
1721import java .io .Reader ;
1822import java .util .Map ;
23+ import java .util .Set ;
1924import java .util .LinkedHashMap ;
2025import java .io .StringReader ;
2126import java .lang .reflect .Array ;
@@ -265,8 +270,6 @@ static String stringifyObject(Object value) {
265270 separator = ", " ;
266271 }
267272 return sb .append ("]" ).toString ();
268- } else if (value instanceof List ) {
269- return stringifyObject (((List ) value ).toArray ());
270273 } else if (value instanceof Map ) {
271274 StringBuilder sb = new StringBuilder ("{" );
272275 String separator = "" ;
@@ -279,6 +282,10 @@ static String stringifyObject(Object value) {
279282 separator = ", " ;
280283 }
281284 return sb .append ("}" ).toString ();
285+ } else if (value instanceof List ) {
286+ return stringifyObject (((List ) value ).toArray ());
287+ } else if (value instanceof Set ) {
288+ return stringifyObject (((Set ) value ).toArray ());
282289 }
283290 return stringifyObject (String .valueOf (value ));
284291// throw new IllegalArgumentException("Unsupported object: "
0 commit comments