Class Decoder

    • Method Detail

      • decode

        public static <T> Result<T> decode​(Value value,
                                           Type dstType)
        Decode a FaunaDB 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));
         
        Type Parameters:
        T - The return type of the method.
        Parameters:
        value - The FaunaDB Value to be decoded.
        dstType - The Type in which value should be decoded.
        Returns:
        A Result instance of type Decoder
        See Also:
        Types, Value.asCollectionOf(Class), Value.asMapOf(Class)
      • decode

        public static <T> Result<T> decode​(Value value,
                                           Class<T> dstType)
        Decode a FaunaDB 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);
         
        Type Parameters:
        T - The return type of the method.
        Parameters:
        value - The FaunaDB Value to be decoded.
        dstType - The Class in which value should be decoded.
        Returns:
        A Result instance of type Decoder
        See Also:
        Value.to(Class)