MCPcopy Index your code
hub / github.com/benfry/processing4 / valueToString

Method valueToString

core/src/processing/data/JSONObject.java:1719–1752  ·  view source on GitHub ↗

Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be used to produce the JSON text. The method is required to produce a strictly conforming text. If the object does not contain a toJSONString method (which is the most common case), then a te

(Object value)

Source from the content-addressed store, hash-verified

1717 * @throws RuntimeException If the value is or contains an invalid number.
1718 */
1719 static protected String valueToString(Object value) {
1720 if (value == null || value.equals(null)) {
1721 return "null";
1722 }
1723// if (value instanceof JSONString) {
1724// Object object;
1725// try {
1726// object = ((JSONString)value).toJSONString();
1727// } catch (Exception e) {
1728// throw new RuntimeException(e);
1729// }
1730// if (object instanceof String) {
1731// return (String)object;
1732// }
1733// throw new RuntimeException("Bad value from toJSONString: " + object);
1734// }
1735 if (value instanceof Number) {
1736 return numberToString((Number) value);
1737 }
1738 if (value instanceof Boolean || value instanceof JSONObject ||
1739 value instanceof JSONArray) {
1740 return value.toString();
1741 }
1742 if (value instanceof Map) {
1743 return new JSONObject(value).toString();
1744 }
1745 if (value instanceof Collection) {
1746 return new JSONArray(value).toString();
1747 }
1748 if (value.getClass().isArray()) {
1749 return new JSONArray(value).toString();
1750 }
1751 return quote(value.toString());
1752 }
1753
1754 /**
1755 * Wrap an object, if necessary. If the object is null, return the NULL

Callers 1

joinMethod · 0.95

Calls 4

numberToStringMethod · 0.95
quoteMethod · 0.95
equalsMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected