public class JsonReader extends java.lang.Object implements ResponseReader
| Constructor and Description |
|---|
JsonReader(com.google.gson.JsonElement element)
A json reader.
|
JsonReader(java.lang.String json)
A json reader.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.gson.JsonElement |
asJson()
Deserialize the returned Json string.
|
java.lang.String |
asPrettyString() |
<T> T |
fromJson(java.lang.Class<T> type)
Deserialize the Json into an object of the specified class.
|
<T> T |
fromJson(com.google.gson.Gson builder,
java.lang.reflect.Type returnType)
Deserialize the Json into an object of the specified class using the supplied builder.
|
<T> T |
fromJson(java.lang.reflect.Type returnType)
Deserialize the Json into an object of the specified class using a default builder.
|
com.google.gson.JsonArray |
getAsJsonArray(com.google.gson.JsonElement node,
java.lang.String path)
Search the JSON response for the requested element.
|
com.google.gson.JsonArray |
getAsJsonArray(java.lang.String path)
Search the JSON response for the requested element.
|
java.lang.String |
getAsString(com.google.gson.JsonElement node,
java.lang.String path)
Search the JSON response for the requested element.
|
java.lang.String |
getAsString(java.lang.String path)
Search the JSON response for the requested element.
|
com.google.gson.JsonElement |
jsonPath(com.google.gson.JsonElement json,
java.lang.String path)
Search a JSON element's children for the requested element.
|
com.google.gson.JsonElement |
jsonPath(java.lang.String path)
Search the JSON response for the requested element.
|
public JsonReader(java.lang.String json)
json - Json stringpublic JsonReader(com.google.gson.JsonElement element)
element - Json Elementpublic java.lang.String asPrettyString()
throws java.io.IOException
asPrettyString in interface ResponseReaderjava.io.IOException - If unable to read the responsepublic com.google.gson.JsonElement asJson()
throws java.io.IOException
JsonElementjava.io.IOException - if the response string is not valid JSONpublic java.lang.String getAsString(java.lang.String path)
jsonPath(String).path - A dot separated Json search pathpublic java.lang.String getAsString(com.google.gson.JsonElement node,
java.lang.String path)
jsonPath(JsonElement, String).node - Json elementpath - A dot separated Json search pathpublic com.google.gson.JsonArray getAsJsonArray(java.lang.String path)
jsonPath(String).path - A dot separated Json search pathpublic com.google.gson.JsonArray getAsJsonArray(com.google.gson.JsonElement node,
java.lang.String path)
jsonPath(JsonElement, String).node - Json elementpath - A dot separated Json search pathpublic com.google.gson.JsonElement jsonPath(java.lang.String path)
JsonElement value = reader.jsonPath("anArray[0].aValue").
String details = (value == null ? "" : value.getAsString());
If an element name contains a dot then the dot can be escaped with a double backslash, eg:
ele1.ele2part1\\.ele2part2
path - A dot separated Json search pathpublic com.google.gson.JsonElement jsonPath(com.google.gson.JsonElement json,
java.lang.String path)
If an element name contains a dot then the dot can be escaped with a double backslash, eg:
ele1.ele2part1\\.ele2part2
json - Json elementpath - A dot separated Json search pathpublic <T> T fromJson(java.lang.Class<T> type)
throws java.io.IOException
Note: use @SerializedName("custom-name") to convert from key name to variable name
T - The type of the desired objecttype - Class to populatejava.io.IOException - if json is not a valid representation for an object of type classOfTpublic <T> T fromJson(java.lang.reflect.Type returnType)
throws com.google.gson.JsonSyntaxException
T - The type of the desired objectreturnType - Class to populatecom.google.gson.JsonSyntaxException - if json is not a valid representation for an object of type classOfTpublic <T> T fromJson(com.google.gson.Gson builder,
java.lang.reflect.Type returnType)
T - The type of the desired objectbuilder - Gson builder to usereturnType - Class to populatecom.google.gson.JsonSyntaxException - if json is not a valid representation for an object of type classOfT