Package com.ibm.cloud.sdk.core.util
Class ResponseUtils
- java.lang.Object
-
- com.ibm.cloud.sdk.core.util.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 ResponseInputStream
.static com.google.gson.JsonElement
getJsonElement(okhttp3.Response response)
Return aJsonElement
representation of the response.static com.google.gson.JsonObject
getJsonObject(java.lang.String jsonString)
Returns aJsonObject
representation of the provided JSON String.static com.google.gson.JsonObject
getJsonObject(okhttp3.Response response)
Returns aJsonObject
representation of the response.static <T extends ObjectModel>
TgetObject(okhttp3.Response response, java.lang.Class<? extends T> type)
Parses theResponse
into the POJO representation.static <T> T
getObject(okhttp3.Response response, java.lang.reflect.Type type)
Parses theResponse
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 theResponse
into a value of the specified type.static <T> T
getValue(okhttp3.Response response, java.lang.reflect.Type valueType)
Parses theResponse
into a value of the specified type.
-
-
-
Method Detail
-
getInputStream
public static java.io.InputStream getInputStream(okhttp3.Response response)
Returns the HTTP ResponseInputStream
.- Parameters:
response
- an HTTP response- Returns:
- the content body as an InputStream
-
getJsonElement
public static com.google.gson.JsonElement getJsonElement(okhttp3.Response response)
Return aJsonElement
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 aJsonObject
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 aJsonObject
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 theResponse
into the POJO representation.- Type Parameters:
T
- the generic type to use when parsing the response- Parameters:
response
- the HTTP responsetype
- the type of the response- Returns:
- the POJO
-
getObject
public static <T> T getObject(okhttp3.Response response, java.lang.reflect.Type type)
Parses theResponse
into the POJO representation.- Type Parameters:
T
- the generic type to use when parsing the response- Parameters:
response
- the HTTP responsetype
- 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 theResponse
into a value of the specified type.- Type Parameters:
T
- the generic type to use when parsing the response- Parameters:
response
- the HTTP responsevalueType
- the type of the response- Returns:
- the value
-
getValue
public static <T> T getValue(okhttp3.Response response, java.lang.reflect.Type valueType)
Parses theResponse
into a value of the specified type.- Type Parameters:
T
- the generic type to use when parsing the response- Parameters:
response
- the HTTP responsevalueType
- 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
-
-