Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update enum support to be more fully featured. #271

Merged
merged 3 commits into from
Aug 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,9 @@ public static String valueToString(Object value) throws JSONException {
if (value.getClass().isArray()) {
return new JSONArray(value).toString();
}
if(value instanceof Enum<?>){
return quote(((Enum<?>)value).name());
}
return quote(value.toString());
}

Expand Down Expand Up @@ -1737,7 +1740,7 @@ public static Object wrap(Object object) {
|| object instanceof Long || object instanceof Boolean
|| object instanceof Float || object instanceof Double
|| object instanceof String || object instanceof BigInteger
|| object instanceof BigDecimal) {
|| object instanceof BigDecimal || object instanceof Enum) {
return object;
}

Expand Down Expand Up @@ -1799,6 +1802,8 @@ static final Writer writeValue(Writer writer, Object value,
writer.write(numberToString((Number) value));
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof Enum<?>) {
writer.write(quote(((Enum<?>)value).name()));
} else if (value instanceof JSONString) {
Object o;
try {
Expand Down