Package io.airlift.json
Class JsonCodec<T>
java.lang.Object
io.airlift.json.JsonCodec<T>
-
Method Summary
Modifier and TypeMethodDescriptionfromJson(byte[] json) Coverts the specified json bytes (UTF-8) into an instance of type T.Converts the specified json string into an instance of type T.getType()Gets the type this codec supports.static <T> JsonCodec<T>jsonCodec(com.google.common.reflect.TypeToken<T> type) static <T> JsonCodec<T>listJsonCodec(JsonCodec<T> type) listJsonCodec(Class<T> type) mapJsonCodec(Class<K> keyType, JsonCodec<V> valueType) mapJsonCodec(Class<K> keyType, Class<V> valueType) Converts the specified instance to json.byte[]toJsonBytes(T instance) Converts the specified instance to json.toJsonWithLengthLimit(T instance, int lengthLimit) Converts the specified instance to optional json string with a length limit.
-
Method Details
-
jsonCodec
-
jsonCodec
-
listJsonCodec
-
listJsonCodec
-
mapJsonCodec
-
mapJsonCodec
-
getType
Gets the type this codec supports. -
fromJson
Converts the specified json string into an instance of type T.- Parameters:
json- the json string to parse- Returns:
- parsed response; never null
- Throws:
IllegalArgumentException- if the json string can not be converted to the type T
-
toJson
Converts the specified instance to json.- Parameters:
instance- the instance to convert to json- Returns:
- json string
- Throws:
IllegalArgumentException- if the specified instance can not be converted to json
-
toJsonWithLengthLimit
Converts the specified instance to optional json string with a length limit. Returns Optional.empty() if length limit is exceeded.- Parameters:
instance- the instance to convert to jsonlengthLimit- the maximum length of the serialized string in characters- Returns:
- json string
- Throws:
IllegalArgumentException- if the specified instance can not be converted to json
-
fromJson
Coverts the specified json bytes (UTF-8) into an instance of type T.- Parameters:
json- the json bytes (UTF-8) to parse- Returns:
- parsed response; never null
- Throws:
IllegalArgumentException- if the json bytes can not be converted to the type T
-
toJsonBytes
Converts the specified instance to json.- Parameters:
instance- the instance to convert to json- Returns:
- json bytes (UTF-8)
- Throws:
IllegalArgumentException- if the specified instance can not be converted to json
-