Skip to content

Commit ddcb469

Browse files
committed
1.0.5
1 parent 61ad637 commit ddcb469

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 miktim@mail.ru
3+
Copyright (c) 2020-2021 miktim@mail.ru
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

readme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Java JSON parser/generator, MIT (c) 2020 miktim@mail.ru
1+
# Java JSON parser/generator, MIT (c) 2020-2021 miktim@mail.ru
22

33
Release notes:
44
- Java SE 7+, Android compatible;
@@ -8,7 +8,7 @@ Release notes:
88
- JSON object members (name/value pairs) are stored in order of appearance/creation;
99
- when the names within an object are not unique, parser stores the last value only;
1010
- JSON object setter accepts any Java object, all Java primitives and primitive arrays;
11-
- in addition to the parsed types, the generator converts Java Lists to JSON arrays
11+
- in addition to the parsed types, the generator converts Java Lists,Sets to JSON arrays
1212
and Java Maps to JSON objects. The null key is converted to a "null" member name.
1313
Other Java objects are converted to JSON strings.
1414

src/org/miktim/json/JSON.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
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
*/
@@ -16,6 +20,7 @@
1620
import java.io.IOException;
1721
import java.io.Reader;
1822
import java.util.Map;
23+
import java.util.Set;
1924
import java.util.LinkedHashMap;
2025
import java.io.StringReader;
2126
import 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

Comments
 (0)