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:
HttpParser, ObjectParser

public final class JsonCParser
extends JsonHttpParser
implements ObjectParser

Parses 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 JsonObjectParser should be used instead.

Sample usage:

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

Implementation is thread-safe.

Since:
1.0
Author:
Yaniv Inbar

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.api.client.http.json.JsonHttpParser
JsonHttpParser.Builder
 
Constructor Summary
JsonCParser(JsonFactory jsonFactory)
           
 
Method Summary
 JsonFactory getFactory()
          Returns the JSON factory used for parsing.
static JsonParser initializeParser(JsonParser parser)
          Initializes a JSON parser to use for parsing by skipping over the "data" or "error" envelope.
<T> T
parse(HttpResponse response, Class<T> dataClass)
          Deprecated. 
<T> T
parseAndClose(InputStream in, Charset charset, Class<T> dataClass)
           
 Object parseAndClose(InputStream in, Charset charset, Type dataType)
           
<T> T
parseAndClose(Reader reader, Class<T> dataClass)
           
 Object parseAndClose(Reader reader, Type dataType)
           
static JsonParser parserForResponse(JsonFactory jsonFactory, HttpResponse response)
          Deprecated. (scheduled to be removed in 1.11) Use JsonFactory.createJsonParser( java.io.InputStream, java.nio.charset.Charset) and initializeParser(JsonParser) instead.
 
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

public JsonCParser(JsonFactory jsonFactory)
Parameters:
jsonFactory - non-null JSON factory used for parsing
Since:
1.5
Method Detail

getFactory

public final JsonFactory getFactory()
Returns the JSON factory used for parsing.

Since:
1.10

parse

@Deprecated
public <T> T parse(HttpResponse response,
                              Class<T> dataClass)
        throws IOException
Deprecated. 

Specified by:
parse in interface HttpParser
Overrides:
parse in class JsonHttpParser
Throws:
IOException

parserForResponse

@Deprecated
public static JsonParser parserForResponse(JsonFactory jsonFactory,
                                                      HttpResponse response)
                                    throws IOException
Deprecated. (scheduled to be removed in 1.11) Use JsonFactory.createJsonParser( java.io.InputStream, java.nio.charset.Charset) and initializeParser(JsonParser) instead.

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 expected "data" or "error" key is not found
IOException - I/O exception
Since:
1.3

initializeParser

public static JsonParser initializeParser(JsonParser parser)
                                   throws IOException
Initializes a JSON parser to use for parsing by skipping over the "data" or "error" envelope.

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

Parameters:
parser - the parser which should be initialized for normal parsing
Throws:
IllegalArgumentException - if content type is not Json.MEDIA_TYPE or if expected "data" or "error" key is not found
IOException
Since:
1.10

parseAndClose

public <T> T parseAndClose(InputStream in,
                           Charset charset,
                           Class<T> dataClass)
                throws IOException
Specified by:
parseAndClose in interface ObjectParser
Throws:
IOException

parseAndClose

public Object parseAndClose(InputStream in,
                            Charset charset,
                            Type dataType)
                     throws IOException
Specified by:
parseAndClose in interface ObjectParser
Throws:
IOException

parseAndClose

public <T> T parseAndClose(Reader reader,
                           Class<T> dataClass)
                throws IOException
Specified by:
parseAndClose in interface ObjectParser
Throws:
IOException

parseAndClose

public Object parseAndClose(Reader reader,
                            Type dataType)
                     throws IOException
Specified by:
parseAndClose in interface ObjectParser
Throws:
IOException


Copyright © 2010-2012 Google. All Rights Reserved.