Class ApiJson<T>

  • Type Parameters:
    T - the type parameter

    public final class ApiJson<T>
    extends Object
    A wrapper around Moshi's JsonAdapter for parsing and formatting JSON for Onfido's API.
    • Constructor Detail

      • ApiJson

        public ApiJson​(Class<T> type)
        Instantiates a new ApiJson object.
        Parameters:
        type - the type
    • Method Detail

      • toJson

        public String toJson​(T t)
        Coverts the provided object of type T to a json string.
        Parameters:
        t - the object to be converted
        Returns:
        the json string
      • toPrettyJson

        public String toPrettyJson​(T t)
        Coverts the provided object of type T to a human readable json string.
        Parameters:
        t - the object to be converted
        Returns:
        the string
      • parse

        public T parse​(String json)
                throws OnfidoException
        Coverts the provided json string to an object of type T
        Parameters:
        json - the json string to be converted
        Returns:
        the object made from the json string
        Throws:
        OnfidoException - the onfido exception
      • parseWrappedList

        public List<T> parseWrappedList​(String json,
                                        String path)
                                 throws OnfidoException
        Parses a json array into a list of type T.
        Parameters:
        json - the json string to be converted
        path - the path to the json array
        Returns:
        the list made from the json string
        Throws:
        OnfidoException - the onfido exception