com.google.api.client.googleapis.json
Class JsonCParser

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

public final class JsonCParser
extends com.google.api.client.http.json.JsonHttpParser

Parses HTTP JSON-C response content into an data class of key/value pairs, assuming the data is wrapped in a "data" envelope.

Warning: this should only be used by some older Google APIs that wrapped the response in a "data" envelope. All newer Google APIs don't use this envelope, and for those APIs JsonHttpParser should be used instead.

Sample usage:

 
  static void setParser(HttpRequest request) {
    request.addParser(new JsonCParser(new JacksonFactory()));
  }
 
 

Since:
1.0
Author:
Yaniv Inbar

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.api.client.http.json.JsonHttpParser
com.google.api.client.http.json.JsonHttpParser.Builder
 
Field Summary
 
Fields inherited from class com.google.api.client.http.json.JsonHttpParser
contentType, jsonFactory
 
Constructor Summary
JsonCParser()
          Deprecated. (scheduled to be removed in 1.6) Use JsonCParser(JsonFactory)
JsonCParser(com.google.api.client.json.JsonFactory jsonFactory)
           
 
Method Summary
<T> T
parse(com.google.api.client.http.HttpResponse response, Class<T> dataClass)
           
static com.google.api.client.json.JsonParser parserForResponse(com.google.api.client.json.JsonFactory jsonFactory, com.google.api.client.http.HttpResponse response)
          Returns a JSON parser to use for parsing the given HTTP response, skipped over the "data" envelope.
 
Methods inherited from class com.google.api.client.http.json.JsonHttpParser
builder, getContentType, getJsonFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonCParser

@Deprecated
public JsonCParser()
Deprecated. (scheduled to be removed in 1.6) Use JsonCParser(JsonFactory)


JsonCParser

public JsonCParser(com.google.api.client.json.JsonFactory jsonFactory)
Parameters:
jsonFactory - JSON factory
Since:
1.5
Method Detail

parse

public <T> T parse(com.google.api.client.http.HttpResponse response,
                   Class<T> dataClass)
        throws IOException
Specified by:
parse in interface com.google.api.client.http.HttpParser
Overrides:
parse in class com.google.api.client.http.json.JsonHttpParser
Throws:
IOException

parserForResponse

public static com.google.api.client.json.JsonParser parserForResponse(com.google.api.client.json.JsonFactory jsonFactory,
                                                                      com.google.api.client.http.HttpResponse response)
                                                               throws IOException
Returns a JSON parser to use for parsing the given HTTP response, skipped over the "data" envelope.

The parser will be closed if any throwable is thrown. The current token will be the value of the "data" key.

Parameters:
response - HTTP response
Returns:
JSON parser
Throws:
IllegalArgumentException - if content type is not Json.CONTENT_TYPE or if "data" key is not found
IOException - I/O exception
Since:
1.3


Copyright © 2010-2011 Google. All Rights Reserved.