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

java.lang.Object
  extended by com.google.api.client.http.AbstractHttpContent
      extended by com.google.api.client.http.json.JsonHttpContent
All Implemented Interfaces:
HttpContent

public class JsonHttpContent
extends AbstractHttpContent

Serializes JSON HTTP content based on the data key/value mapping object for an item.

Sample usage:

 
  static void setContent(HttpRequest request, Object data) {
    request.setContent(new JsonHttpContent(new JacksonFactory(), data));
  }
 
 

Implementation is not thread-safe.

Since:
1.0
Author:
Yaniv Inbar

Constructor Summary
JsonHttpContent(JsonFactory jsonFactory, Object data)
           
 
Method Summary
 Object getData()
          Returns the JSON key name/value data.
 JsonFactory getJsonFactory()
          Returns the JSON factory.
 JsonHttpContent setMediaType(HttpMediaType mediaType)
          Sets the media type to use for the Content-Type header, or null if unspecified.
 JsonHttpContent setType(String type)
          Deprecated. (scheduled to be removed in 1.11) Use setMediaType(HttpMediaType) instead.
 void writeTo(OutputStream out)
          Writes the content to the given output stream.
 
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, getCharset, getEncoding, getLength, getMediaType, getType, retrySupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonHttpContent

public JsonHttpContent(JsonFactory jsonFactory,
                       Object data)
Parameters:
jsonFactory - JSON factory to use
data - JSON key name/value data
Since:
1.5
Method Detail

writeTo

public void writeTo(OutputStream out)
             throws IOException
Description copied from interface: HttpContent
Writes the content to the given output stream.

The recommendation for implementations is that they should not close the output stream. Callers should not assume whether or not the output stream has been closed. Implementations that do not close the output stream should flush it at the end of the method.

Throws:
IOException

setType

@Deprecated
public JsonHttpContent setType(String type)
Deprecated. (scheduled to be removed in 1.11) Use setMediaType(HttpMediaType) instead.

Sets the content type or null for none.

Defaults to Json.CONTENT_TYPE.

Since:
1.5

setMediaType

public JsonHttpContent setMediaType(HttpMediaType mediaType)
Description copied from class: AbstractHttpContent
Sets the media type to use for the Content-Type header, or null if unspecified.

This will also overwrite any previously set parameter of the media type (for example "charset"), and therefore might change other properties as well.

Overrides:
setMediaType in class AbstractHttpContent

getData

public final Object getData()
Returns the JSON key name/value data.

Since:
1.5

getJsonFactory

public final JsonFactory getJsonFactory()
Returns the JSON factory.

Since:
1.5


Copyright © 2011-2012 Google. All Rights Reserved.