public class JsonCodec extends Object
Supported types are
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY_TYPE
Type id for a complex type array containing a
JsonArray . |
static int |
NODE_TYPE
Type id for a complex type array containing an
Element . |
static int |
RETURN_CHANNEL_TYPE
Type id for a complex type array identifying a
ReturnChannelRegistration reference. |
Modifier and Type | Method and Description |
---|---|
static boolean |
canEncodeWithoutTypeInfo(Class<?> type)
Helper for checking whether the type is supported by
encodeWithoutTypeInfo(Object) . |
static boolean |
canEncodeWithTypeInfo(Class<?> type)
Helper for checking whether the type is supported by
encodeWithTypeInfo(Object) . |
static <T> T |
decodeAs(elemental.json.JsonValue json,
Class<T> type)
Decodes the given JSON value as the given type.
|
static Serializable |
decodeWithoutTypeInfo(elemental.json.JsonValue json)
Helper for decoding any "primitive" value that is directly supported in
JSON.
|
static elemental.json.JsonValue |
encodeWithConstantPool(Object value,
ConstantPool constantPool)
Encodes a "primitive" value or a constant pool reference to JSON.
|
static elemental.json.JsonValue |
encodeWithoutTypeInfo(Object value)
Helper for encoding any "primitive" value that is directly supported in
JSON.
|
static elemental.json.JsonValue |
encodeWithTypeInfo(Object value)
Helper for encoding values that might not have a native representation in
JSON.
|
public static final int NODE_TYPE
Element
.public static final int ARRAY_TYPE
JsonArray
.public static final int RETURN_CHANNEL_TYPE
ReturnChannelRegistration
reference.public static elemental.json.JsonValue encodeWithTypeInfo(Object value)
encodeWithoutTypeInfo(Object)
, Element
and
Component
(encoded as its root element).value
- the value to encodepublic static boolean canEncodeWithoutTypeInfo(Class<?> type)
encodeWithoutTypeInfo(Object)
. Supported value types are
String
, Integer
, Double
, Boolean
,
JsonValue
.type
- the type to checkpublic static boolean canEncodeWithTypeInfo(Class<?> type)
encodeWithTypeInfo(Object)
. Supported values types are
Node
, Component
, ReturnChannelRegistration
and
anything accepted by canEncodeWithoutTypeInfo(Class)
.type
- the type to checkpublic static elemental.json.JsonValue encodeWithConstantPool(Object value, ConstantPool constantPool)
ConstantPoolKey
in addition to the types
supported by encodeWithoutTypeInfo(Object)
.value
- the value to encodeconstantPool
- the constant pool to use for encoding constant pool referencespublic static elemental.json.JsonValue encodeWithoutTypeInfo(Object value)
String
, Number
,
Boolean
, JsonValue
. null
is also supported.value
- the value to encodepublic static Serializable decodeWithoutTypeInfo(elemental.json.JsonValue json)
String
, Number
,
Boolean
, JsonValue
. null
is also supported.json
- the JSON value to decodepublic static <T> T decodeAs(elemental.json.JsonValue json, Class<T> type)
Supported types are String
, Boolean
, Integer
,
Double
and primitives boolean, int, double
T
- the decoded typejson
- the JSON valuetype
- the type to decode asIllegalArgumentException
- if the type was unsupportedCopyright © 2020. All rights reserved.