Skip to content

Commit ebe69df

Browse files
authored
Merge pull request stleary#271 from johnjaylward/EnumCleanup
Update enum support to be more fully featured.
2 parents 7232a95 + 349a209 commit ebe69df

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

JSONObject.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,9 @@ public static String valueToString(Object value) throws JSONException {
17101710
if (value.getClass().isArray()) {
17111711
return new JSONArray(value).toString();
17121712
}
1713+
if(value instanceof Enum<?>){
1714+
return quote(((Enum<?>)value).name());
1715+
}
17131716
return quote(value.toString());
17141717
}
17151718

@@ -1737,7 +1740,7 @@ public static Object wrap(Object object) {
17371740
|| object instanceof Long || object instanceof Boolean
17381741
|| object instanceof Float || object instanceof Double
17391742
|| object instanceof String || object instanceof BigInteger
1740-
|| object instanceof BigDecimal) {
1743+
|| object instanceof BigDecimal || object instanceof Enum) {
17411744
return object;
17421745
}
17431746

@@ -1799,6 +1802,8 @@ static final Writer writeValue(Writer writer, Object value,
17991802
writer.write(numberToString((Number) value));
18001803
} else if (value instanceof Boolean) {
18011804
writer.write(value.toString());
1805+
} else if (value instanceof Enum<?>) {
1806+
writer.write(quote(((Enum<?>)value).name()));
18021807
} else if (value instanceof JSONString) {
18031808
Object o;
18041809
try {

0 commit comments

Comments
 (0)