Skip to content

Commit

Permalink
fix(http): return numbers and booleans as-is when application/json is…
Browse files Browse the repository at this point in the history
… the content type
  • Loading branch information
ItsChaceD authored Aug 22, 2023
1 parent ae35e29 commit 03dd3f9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,18 @@ public static Object parseJSON(String input) throws JSONException {
if ("null".equals(input.trim())) {
return JSONObject.NULL;
} else if ("true".equals(input.trim())) {
return new JSONObject().put("flag", "true");
return true;
} else if ("false".equals(input.trim())) {
return new JSONObject().put("flag", "false");
return false;
} else if (input.trim().length() <= 0) {
return "";
} else if (input.trim().matches("^\".*\"$")) {
// a string enclosed in " " is a json value, return the string without the quotes
return input.trim().substring(1, input.trim().length() - 1);
} else if (input.trim().matches("^-?\\d+$")) {
return Integer.parseInt(input.trim());
} else if (input.trim().matches("^-?\\d+(\\.\\d+)?$")) {
return Double.parseDouble(input.trim());
} else {
try {
return new JSObject(input);
Expand All @@ -318,7 +322,7 @@ public static Object parseJSON(String input) throws JSONException {
}
}
} catch (JSONException e) {
return new JSArray(input);
return input;
}
}

Expand Down

0 comments on commit 03dd3f9

Please sign in to comment.