MCPcopy
hub / github.com/jOOQ/jOOQ / toJSONString

Method toJSONString

jOOQ/src/main/java/org/jooq/tools/json/JSONObject.java:89–109  ·  view source on GitHub ↗

Convert a map to JSON text. The result is a JSON object. @see JSONValue#toJSONString(Object) @return JSON text, or "null" if map is null.

(Map<?, ?> map)

Source from the content-addressed store, hash-verified

87 * @return JSON text, or "null" if map is null.
88 */
89 public static String toJSONString(Map<?, ?> map) {
90 if (map == null)
91 return "null";
92
93 StringBuffer sb = new StringBuffer();
94 boolean first = true;
95 Iterator<?> iter = map.entrySet().iterator();
96
97 sb.append('{');
98 while (iter.hasNext()) {
99 if (first)
100 first = false;
101 else
102 sb.append(',');
103
104 Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next();
105 toJSONString(String.valueOf(entry.getKey()), entry.getValue(), sb);
106 }
107 sb.append('}');
108 return sb.toString();
109 }
110
111 private static String toJSONString(String key, Object value, StringBuffer sb) {
112 sb.append('\"');

Callers 1

toStringMethod · 0.95

Calls 11

escapeMethod · 0.95
toJSONStringMethod · 0.95
iteratorMethod · 0.65
appendMethod · 0.65
hasNextMethod · 0.65
nextMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
toStringMethod · 0.65
entrySetMethod · 0.45
valueOfMethod · 0.45

Tested by

no test coverage detected