Package com.vaadin.client.flow.util
Class ClientJsonCodec
- java.lang.Object
-
- com.vaadin.client.flow.util.ClientJsonCodec
-
public class ClientJsonCodec extends Object
Static helpers for encoding and decoding JSON.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StateNodedecodeStateNode(StateTree tree, elemental.json.JsonValue json)Decodes a value as aStateNodeencoded on the server usingJsonCodec.encodeWithTypeInfo(Object)if it's possible.static ObjectdecodeWithoutTypeInfo(elemental.json.JsonValue json)Decodes a value encoded on the server usingJsonCodec.encodeWithoutTypeInfo(Object).static ObjectdecodeWithTypeInfo(StateTree tree, elemental.json.JsonValue json)Decodes a value encoded on the server usingJsonCodec.encodeWithTypeInfo(Object).static elemental.json.JsonValueencodeWithoutTypeInfo(Object value)Helper for encoding any "primitive" value that is directly supported in JSON.static JsArray<Object>jsonArrayAsJsArray(elemental.json.JsonArray jsonArray)Converts a JSON array to a JS array.
-
-
-
Method Detail
-
decodeStateNode
public static StateNode decodeStateNode(StateTree tree, elemental.json.JsonValue json)
Decodes a value as aStateNodeencoded on the server usingJsonCodec.encodeWithTypeInfo(Object)if it's possible. Otherwise returnsnull.It does the same as
decodeWithTypeInfo(StateTree, JsonValue)for the encoded json value if the encoded object is aStateNodeexcept it returns the node itself instead of a DOM element associated with it.- Parameters:
tree- the state tree to use for resolving nodes and elementsjson- the JSON value to decode- Returns:
- the decoded state node if any
- See Also:
decodeWithTypeInfo(StateTree, JsonValue)
-
decodeWithTypeInfo
public static Object decodeWithTypeInfo(StateTree tree, elemental.json.JsonValue json)
Decodes a value encoded on the server usingJsonCodec.encodeWithTypeInfo(Object).- Parameters:
tree- the state tree to use for resolving nodes and elementsjson- the JSON value to decode- Returns:
- the decoded value
-
decodeWithoutTypeInfo
public static Object decodeWithoutTypeInfo(elemental.json.JsonValue json)
Decodes a value encoded on the server usingJsonCodec.encodeWithoutTypeInfo(Object). This is a no-op in compiled JavaScript since the JSON representation can be used as-is, but some special handling is needed for tests running in the JVM.- Parameters:
json- the JSON value to convert- Returns:
- the decoded Java value
-
encodeWithoutTypeInfo
public static elemental.json.JsonValue encodeWithoutTypeInfo(Object value)
Helper for encoding any "primitive" value that is directly supported in JSON. Supported values types areString,Number,Boolean,JsonValue.nullis also supported.- Parameters:
value- the value to encode- Returns:
- the value encoded as JSON
-
jsonArrayAsJsArray
public static JsArray<Object> jsonArrayAsJsArray(elemental.json.JsonArray jsonArray)
Converts a JSON array to a JS array. This is a no-op in compiled JavaScript, but needs special handling for tests running in the JVM.- Parameters:
jsonArray- the JSON array to convert- Returns:
- the converted JS array
-
-