public final class Decoder
extends java.lang.Object
Value to object decoder.
The Decoder is capable of decoding user defined classes as long
as properly annotated with: FaunaField, FaunaConstructor, FaunaIgnore, and FaunaEnum.| Modifier and Type | Method and Description |
|---|---|
static <T> Result<T> |
decode(Value value,
java.lang.Class<T> dstType)
Decode a FaunaDB
Value to a specified type. |
static <T> Result<T> |
decode(Value value,
java.lang.reflect.Type dstType)
Decode a FaunaDB
Value to a specified type. |
public static <T> Result<T> decode(Value value, java.lang.reflect.Type dstType)
Value to a specified type.
This method is useful if you need to decode collections or key/value maps.
Result<List<String>> listStrings = Decoder.decode(result, Types.arrayListOf(String.class));
Result<Set<String>> setStrings = Decoder.decode(result, Types.hashSetOf(String.class));
T - The return type of the method.value - The FaunaDB Value to be decoded.dstType - The Type in which value should be decoded.Result instance of type TTypes,
Value.asCollectionOf(Class),
Value.asMapOf(Class)public static <T> Result<T> decode(Value value, java.lang.Class<T> dstType)
Value to a specified type.
Use this method to decode user defined types like:
Result<User> user = Decoder.decode(result, User.class);
It's possible to decode primitive types and arrays of primitive types
Result<String> string = Decoder.decode(result, String.class);
Result<long> longValue = Decoder.decode(result, long.class);
Result<int> intValue = Decoder.decode(result, int.class);
Result<int[]> arrayInt = Decoder.decode(result, int[].class);
T - The return type of the method.value - The FaunaDB Value to be decoded.dstType - The Class in which value should be decoded.Result instance of type TValue.to(Class)