public class JsonHttpContent extends AbstractHttpContent
Sample usage:
static void setContent(HttpRequest request, Object data) {
request.setContent(new JsonHttpContent(new JacksonFactory(), data));
}
Implementation is not thread-safe.
Constructor and Description |
---|
JsonHttpContent(JsonFactory jsonFactory,
Object data) |
Modifier and Type | Method and Description |
---|---|
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. |
void |
writeTo(OutputStream out)
Writes the content to the given output stream.
|
computeLength, getCharset, getEncoding, getLength, getMediaType, getType, retrySupported
public JsonHttpContent(JsonFactory jsonFactory, Object data)
jsonFactory
- JSON factory to usedata
- JSON key name/value datapublic void writeTo(OutputStream out) throws IOException
HttpContent
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.
IOException
public JsonHttpContent setMediaType(HttpMediaType mediaType)
AbstractHttpContent
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.
setMediaType
in class AbstractHttpContent
public final Object getData()
public final JsonFactory getJsonFactory()
Copyright © 2011-2012 Google. All Rights Reserved.