Package com.faunadb.client.types
Class Decoder
- java.lang.Object
-
- com.faunadb.client.types.Decoder
-
public final class Decoder extends Object
FaunaDBValue
to object decoder. TheDecoder
is capable of decoding user defined classes as long as properly annotated with:FaunaField
,FaunaConstructor
,FaunaIgnore
, andFaunaEnum
.
-
-
Method Detail
-
decode
public static <T> Result<T> decode(Value value, Type dstType)
Decode a FaunaDBValue
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));
- Type Parameters:
T
- The return type of the method.- Parameters:
value
- The FaunaDBValue
to be decoded.dstType
- TheType
in which value should be decoded.- Returns:
- A
Result
instance of typeDecoder
- See Also:
Types
,Value.asCollectionOf(Class)
,Value.asMapOf(Class)
-
decode
public static <T> Result<T> decode(Value value, Class<T> dstType)
Decode a FaunaDBValue
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);
- Type Parameters:
T
- The return type of the method.- Parameters:
value
- The FaunaDBValue
to be decoded.dstType
- TheClass
in which value should be decoded.- Returns:
- A
Result
instance of typeDecoder
- See Also:
Value.to(Class)
-
-