Class ResponseUtils


  • public final class ResponseUtils
    extends java.lang.Object
    Utility class to manage service responses.
    See Also:
    Response
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.InputStream getInputStream​(okhttp3.Response response)
      Returns the HTTP Response InputStream.
      static com.google.gson.JsonElement getJsonElement​(okhttp3.Response response)
      Return a JsonElement representation of the response.
      static com.google.gson.JsonObject getJsonObject​(java.lang.String jsonString)
      Returns a JsonObject representation of the provided JSON String.
      static com.google.gson.JsonObject getJsonObject​(okhttp3.Response response)
      Returns a JsonObject representation of the response.
      static <T extends ObjectModel>
      T
      getObject​(okhttp3.Response response, java.lang.Class<? extends T> type)
      Parses the Response into the POJO representation.
      static <T> T getObject​(okhttp3.Response response, java.lang.reflect.Type type)
      Parses the Response into the POJO representation.
      static java.lang.String getString​(okhttp3.Response response)
      Returns a String representation of the response.
      static <T> T getValue​(okhttp3.Response response, java.lang.Class<? extends T> valueType)
      Parses the Response into a value of the specified type.
      static <T> T getValue​(okhttp3.Response response, java.lang.reflect.Type valueType)
      Parses the Response into a value of the specified type.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInputStream

        public static java.io.InputStream getInputStream​(okhttp3.Response response)
        Returns the HTTP Response InputStream.
        Parameters:
        response - an HTTP response
        Returns:
        the content body as an InputStream
      • getJsonElement

        public static com.google.gson.JsonElement getJsonElement​(okhttp3.Response response)
        Return a JsonElement representation of the response.
        Parameters:
        response - the Response
        Returns:
        the content body as JSON
      • getJsonObject

        public static com.google.gson.JsonObject getJsonObject​(okhttp3.Response response)
        Returns a JsonObject representation of the response.
        Parameters:
        response - an HTTP response
        Returns:
        the content body as JSONArray
      • getJsonObject

        public static com.google.gson.JsonObject getJsonObject​(java.lang.String jsonString)
        Returns a JsonObject representation of the provided JSON String.
        Parameters:
        jsonString - the JSON String
        Returns:
        the content body as a JsonObject
      • getObject

        public static <T extends ObjectModel> T getObject​(okhttp3.Response response,
                                                          java.lang.Class<? extends T> type)
        Parses the Response into the POJO representation.
        Type Parameters:
        T - the generic type to use when parsing the response
        Parameters:
        response - the HTTP response
        type - the type of the response
        Returns:
        the POJO
      • getObject

        public static <T> T getObject​(okhttp3.Response response,
                                      java.lang.reflect.Type type)
        Parses the Response into the POJO representation.
        Type Parameters:
        T - the generic type to use when parsing the response
        Parameters:
        response - the HTTP response
        type - a Type instance which describes the type of the response
        Returns:
        the POJO
      • getValue

        public static <T> T getValue​(okhttp3.Response response,
                                     java.lang.Class<? extends T> valueType)
        Parses the Response into a value of the specified type.
        Type Parameters:
        T - the generic type to use when parsing the response
        Parameters:
        response - the HTTP response
        valueType - the type of the response
        Returns:
        the value
      • getValue

        public static <T> T getValue​(okhttp3.Response response,
                                     java.lang.reflect.Type valueType)
        Parses the Response into a value of the specified type.
        Type Parameters:
        T - the generic type to use when parsing the response
        Parameters:
        response - the HTTP response
        valueType - a Type instance which describes the type associated with the response
        Returns:
        the value
      • getString

        public static java.lang.String getString​(okhttp3.Response response)
        Returns a String representation of the response.
        Parameters:
        response - an HTTP response
        Returns:
        the content body as String