Package com.vaadin.client.flow.util
Class ClientJsonCodec
java.lang.Object
com.vaadin.client.flow.util.ClientJsonCodec
Static helpers for encoding and decoding JSON.
- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.jsonArrayAsJsArray(elemental.json.JsonArray jsonArray) Converts a JSON array to a JS array.
-
Method Details
-
decodeStateNode
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
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
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
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
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
-