com.google.api.client.http.json
Class JsonHttpParser

java.lang.Object
  extended by com.google.api.client.http.json.JsonHttpParser
All Implemented Interfaces:
HttpParser

public class JsonHttpParser
extends Object
implements HttpParser

Parses HTTP JSON response content into an data class of key/value pairs.

Sample usage:

 
  static void setParser(HttpTransport transport) {
    JsonHttpParser parser = new JsonHttpParser();
    parser.jsonFactory = new JacksonFactory();
    transport.addParser(parser);
  }
 
 

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 String contentType
          Content type.
 JsonFactory jsonFactory
          (Required) JSON factory to use.
 
Constructor Summary
JsonHttpParser()
           
 
Method Summary
 String getContentType()
          Returns the content type.
<T> T
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
 

Field Detail

contentType

public String contentType
Content type. Default value is Json.CONTENT_TYPE.


jsonFactory

public JsonFactory jsonFactory
(Required) JSON factory to use.

Since:
1.3
Constructor Detail

JsonHttpParser

public JsonHttpParser()
Method Detail

getContentType

public final String getContentType()
Description copied from interface: HttpParser
Returns the content type.

Specified by:
getContentType in interface HttpParser

parse

public <T> T parse(HttpResponse response,
                   Class<T> dataClass)
        throws IOException
Description copied from interface: HttpParser
Parses the given HTTP response into a new instance of the the given data class of key/value pairs.

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.

Specified by:
parse in interface HttpParser
Throws:
IOException

parserForResponse

public static JsonParser parserForResponse(JsonFactory jsonFactory,
                                           HttpResponse response)
                                    throws IOException
Returns a JSON parser to use for parsing the given HTTP response.

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.

Parameters:
jsonFactory - JSON factory to use
response - HTTP response
Returns:
JSON parser
Throws:
IllegalArgumentException - if content type is not Json.CONTENT_TYPE
IOException - I/O exception
Since:
1.3


Copyright © 2010-2011 Google. All Rights Reserved.