Class ClientJsonCodec


  • public class ClientJsonCodec
    extends Object
    Static helpers for encoding and decoding JSON.
    Since:
    1.0
    Author:
    Vaadin Ltd
    • Method Detail

      • decodeWithTypeInfo

        public static Object decodeWithTypeInfo​(StateTree tree,
                                                elemental.json.JsonValue json)
        Decodes a value encoded on the server using JsonCodec.encodeWithTypeInfo(Object).
        Parameters:
        tree - the state tree to use for resolving nodes and elements
        json - 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 using JsonCodec.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 are String, Number, Boolean, JsonValue. null is 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