Class TeaVmJson
java.lang.Object
net.sourceforge.plantuml.teavm.headless.TeaVmJson
Small TeaVM helper to build JSON results from Java without hand-rolling the
escaping.
Instead of assembling JSON text character by character (and getting quoting,
newlines and control-character escapes right by hand), the headless entry
point builds a native JS object/array through these @JSBody helpers
and serializes it with the platform's JSON.stringify. This mirrors
the stringify helper already used by
TeaVmScriptLoader.
All methods are TeaVM-only (they compile to plain JS); they are not meant to be called from a normal JVM.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddStringSafe(org.teavm.jso.JSObject json, String key, String value) static org.teavm.jso.JSObjectnewArray()static org.teavm.jso.JSObjectstatic voidAppends a string to a JS array.static voidpushObject(org.teavm.jso.JSObject arr, org.teavm.jso.JSObject value) Appends a nested object/array to a JS array.static voidputBoolean(org.teavm.jso.JSObject obj, String key, boolean value) Setsobj[key] = valuefor a boolean value.static voidSetsobj[key] = valuefor an integer value.static voidSetsobj[key] = valuefor a nested object/array value.static voidSetsobj[key] = valuefor a string value.static Stringstringify(org.teavm.jso.JSObject obj) Serializes a JS object/array to a JSON string with the nativeJSON.stringify.
-
Method Details
-
newObject
public static org.teavm.jso.JSObject newObject()- Returns:
- a fresh, empty JS object (
{}).
-
newArray
public static org.teavm.jso.JSObject newArray()- Returns:
- a fresh, empty JS array (
[]).
-
putString
Setsobj[key] = valuefor a string value. -
addStringSafe
-
putInt
Setsobj[key] = valuefor an integer value. -
putBoolean
Setsobj[key] = valuefor a boolean value. -
putObject
Setsobj[key] = valuefor a nested object/array value. -
push
Appends a string to a JS array. -
pushObject
public static void pushObject(org.teavm.jso.JSObject arr, org.teavm.jso.JSObject value) Appends a nested object/array to a JS array. -
stringify
Serializes a JS object/array to a JSON string with the nativeJSON.stringify.- Parameters:
obj- a JS object or array- Returns:
- its JSON representation, or
nullifobjis null
-