public class JsonCodec<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
T |
fromJson(byte[] json)
Coverts the specified json bytes (UTF-8) into an instance of type T.
|
T |
fromJson(String json)
Converts the specified json string into an instance of type T.
|
Type |
getType()
Gets the type this codec supports.
|
static <T> JsonCodec<T> |
jsonCodec(Class<T> type) |
static <T> JsonCodec<T> |
jsonCodec(com.google.common.reflect.TypeToken<T> type) |
static <T> JsonCodec<List<T>> |
listJsonCodec(Class<T> type) |
static <T> JsonCodec<List<T>> |
listJsonCodec(JsonCodec<T> type) |
static <K,V> JsonCodec<Map<K,V>> |
mapJsonCodec(Class<K> keyType,
Class<V> valueType) |
static <K,V> JsonCodec<Map<K,V>> |
mapJsonCodec(Class<K> keyType,
JsonCodec<V> valueType) |
String |
toJson(T instance)
Converts the specified instance to json.
|
byte[] |
toJsonBytes(T instance)
Converts the specified instance to json.
|
public static <T> JsonCodec<T> jsonCodec(com.google.common.reflect.TypeToken<T> type)
public static <K,V> JsonCodec<Map<K,V>> mapJsonCodec(Class<K> keyType, Class<V> valueType)
public static <K,V> JsonCodec<Map<K,V>> mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType)
public Type getType()
public T fromJson(String json) throws IllegalArgumentException
json - the json string to parseIllegalArgumentException - if the json string can not be converted to the type Tpublic String toJson(T instance) throws IllegalArgumentException
instance - the instance to convert to jsonIllegalArgumentException - if the specified instance can not be converted to jsonpublic T fromJson(byte[] json) throws IllegalArgumentException
json - the json bytes (UTF-8) to parseIllegalArgumentException - if the json bytes can not be converted to the type Tpublic byte[] toJsonBytes(T instance) throws IllegalArgumentException
instance - the instance to convert to jsonIllegalArgumentException - if the specified instance can not be converted to jsonCopyright © 2010-2016 Airlift. All Rights Reserved.