Class JsonCodec
java.lang.Object
com.flowingcode.vaadin.jsonmigration.JsonCodec
Utility for encoding objects to and from JSON.
Supported types are
- Author:
- Vaadin Ltd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanEncodeWithoutTypeInfo(Class<?> type) Helper for checking whether the type is supported byencodeWithoutTypeInfo(Object).static <T> TDecodes the given JSON value as the given type.static elemental.json.JsonValueencodeWithoutTypeInfo(Object value) Helper for encoding any "primitive" value that is directly supported in JSON.
-
Constructor Details
-
JsonCodec
public JsonCodec()
-
-
Method Details
-
decodeAs
Decodes the given JSON value as the given type.Supported types are
String,Boolean,Integer,Doubleand primitives boolean, int, double- Type Parameters:
T- the decoded type- Parameters:
json- the JSON valuetype- the type to decode as- Returns:
- the value decoded as the given type
- Throws:
IllegalArgumentException- if the type was unsupported
-
canEncodeWithoutTypeInfo
Helper for checking whether the type is supported byencodeWithoutTypeInfo(Object). Supported value types areString,Integer,Double,Boolean,JsonValue.- Parameters:
type- the type to check- Returns:
- whether the type can be encoded
-
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
-