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.ObjectUtility class to manage service responses.- See Also:
Response
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.InputStreamgetInputStream(okhttp3.Response response)Returns the HTTP ResponseInputStream.static com.google.gson.JsonElementgetJsonElement(okhttp3.Response response)Return aJsonElementrepresentation of the response.static com.google.gson.JsonObjectgetJsonObject(java.lang.String jsonString)Returns aJsonObjectrepresentation of the provided JSON String.static com.google.gson.JsonObjectgetJsonObject(okhttp3.Response response)Returns aJsonObjectrepresentation of the response.static <T extends ObjectModel>
TgetObject(okhttp3.Response response, java.lang.Class<? extends T> type)Parses theResponseinto the POJO representation.static <T> TgetObject(okhttp3.Response response, java.lang.reflect.Type type)Parses theResponseinto the POJO representation.static java.lang.StringgetString(okhttp3.Response response)Returns a String representation of the response.static <T> TgetValue(okhttp3.Response response, java.lang.Class<? extends T> valueType)Parses theResponseinto a value of the specified type.static <T> TgetValue(okhttp3.Response response, java.lang.reflect.Type valueType)Parses theResponseinto 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 aJsonElementrepresentation 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 aJsonObjectrepresentation 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 aJsonObjectrepresentation 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 theResponseinto 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 theResponseinto 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 theResponseinto 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 theResponseinto 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
-
-