Class ApiResponse<T>

  • Type Parameters:
    T - Type of the result

    public class ApiResponse<T>
    extends Object
    A container that parse an API response
    Author:
    Cadiducho
    • Constructor Detail

      • ApiResponse

        public ApiResponse()
    • Method Detail

      • toJson

        public String toJson()
        Serialize this response to json
        Returns:
        String that contains the serialized response
      • from

        public static <T> ApiResponse<T> from​(String source,
                                              Type resultType)
                                       throws IOException
        Create an ApiResponse object from a String
        Type Parameters:
        T - Type of the result
        Parameters:
        source - String fetched from the API
        resultType - Class of the result
        Returns:
        An ApiResponse object with that data
        Throws:
        IOException - If Moshi fails
      • from

        public static <T> ApiResponse<T> from​(okio.BufferedSource source,
                                              Type resultType)
                                       throws IOException
        Create an ApiResponse object from a BufferedSource
        Type Parameters:
        T - Type of the result
        Parameters:
        source - String fetched from the API
        resultType - Class of the result
        Returns:
        An ApiResponse object with that data
        Throws:
        IOException - If Moshi fails