|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.api.client.http.json.JsonHttpParser
public class JsonHttpParser
Parses HTTP JSON response content into an data class of key/value pairs.
Implementation is thread-safe.
Sample usage:
static void setParser(HttpRequest request) {
request.addParser(new JsonHttpParser(new JacksonFactory()));
}
Nested Class Summary | |
---|---|
static class |
JsonHttpParser.Builder
Builder for JsonHttpParser . |
Constructor Summary | |
---|---|
|
JsonHttpParser(JsonFactory jsonFactory)
Constructor with required parameters. |
protected |
JsonHttpParser(JsonFactory jsonFactory,
String contentType)
|
Method Summary | ||
---|---|---|
static JsonHttpParser.Builder |
builder(JsonFactory jsonFactory)
Returns an instance of a new builder. |
|
String |
getContentType()
Returns the content type. |
|
JsonFactory |
getJsonFactory()
Returns the JSON factory. |
|
|
parse(HttpResponse response,
Class<T> dataClass)
Parses the given HTTP response into a new instance of the the given data class of key/value pairs. |
|
static JsonParser |
parserForResponse(JsonFactory jsonFactory,
HttpResponse response)
Returns a JSON parser to use for parsing the given HTTP response. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JsonHttpParser(JsonFactory jsonFactory)
Use builder(com.google.api.client.json.JsonFactory)
if you need to specify any of the optional parameters.
jsonFactory
- JSON factoryprotected JsonHttpParser(JsonFactory jsonFactory, String contentType)
jsonFactory
- JSON factorycontentType
- content type or null
for noneMethod Detail |
---|
public final String getContentType()
HttpParser
getContentType
in interface HttpParser
public <T> T parse(HttpResponse response, Class<T> dataClass) throws IOException
HttpParser
How the parsing is performed is not restricted by this interface, and is instead defined by the
concrete implementation. Implementations should check
HttpResponse.isSuccessStatusCode()
to know whether they are parsing a success or error
response.
parse
in interface HttpParser
IOException
public final JsonFactory getJsonFactory()
public static JsonParser parserForResponse(JsonFactory jsonFactory, HttpResponse response) throws IOException
The response content will be closed if any throwable is thrown. On success, the current token
will be the first top token, which is normally JsonToken.START_ARRAY
or
JsonToken.START_OBJECT
.
jsonFactory
- JSON factory to useresponse
- HTTP response
IllegalArgumentException
- if content type is not Json.CONTENT_TYPE
IOException
public static JsonHttpParser.Builder builder(JsonFactory jsonFactory)
jsonFactory
- JSON factory
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |