Package com.google.api.client.http.json
Class JsonHttpContent
- java.lang.Object
-
- com.google.api.client.http.AbstractHttpContent
-
- com.google.api.client.http.json.JsonHttpContent
-
- All Implemented Interfaces:
HttpContent,StreamingContent
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
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ObjectdataJSON key name/value data.private JsonFactoryjsonFactoryJSON factory.private java.lang.StringwrapperKeyWrapper key for the JSON content ornullfor none.
-
Constructor Summary
Constructors Constructor Description JsonHttpContent(JsonFactory jsonFactory, java.lang.Object data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectgetData()Returns the JSON key name/value data.JsonFactorygetJsonFactory()Returns the JSON factory.java.lang.StringgetWrapperKey()Returns the wrapper key for the JSON content ornullfor none.JsonHttpContentsetMediaType(HttpMediaType mediaType)Sets the media type to use for the Content-Type header, ornullif unspecified.JsonHttpContentsetWrapperKey(java.lang.String wrapperKey)Sets the wrapper key for the JSON content ornullfor none.voidwriteTo(java.io.OutputStream out)Writes the byte content to the given output stream.-
Methods inherited from class com.google.api.client.http.AbstractHttpContent
computeLength, computeLength, getCharset, getLength, getMediaType, getType, retrySupported
-
-
-
-
Field Detail
-
data
private final java.lang.Object data
JSON key name/value data.
-
jsonFactory
private final JsonFactory jsonFactory
JSON factory.
-
wrapperKey
private java.lang.String wrapperKey
Wrapper key for the JSON content ornullfor none.
-
-
Constructor Detail
-
JsonHttpContent
public JsonHttpContent(JsonFactory jsonFactory, java.lang.Object data)
- Parameters:
jsonFactory- JSON factory to usedata- JSON key name/value data- Since:
- 1.5
-
-
Method Detail
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionDescription copied from interface:StreamingContentWrites the byte content to the given output stream.Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the the output stream has not been closed, and will fail to work if it has been closed.
- Parameters:
out- output stream- Throws:
java.io.IOException
-
setMediaType
public JsonHttpContent setMediaType(HttpMediaType mediaType)
Description copied from class:AbstractHttpContentSets the media type to use for the Content-Type header, ornullif 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:
setMediaTypein classAbstractHttpContent
-
getData
public final java.lang.Object getData()
Returns the JSON key name/value data.- Since:
- 1.5
-
getJsonFactory
public final JsonFactory getJsonFactory()
Returns the JSON factory.- Since:
- 1.5
-
getWrapperKey
public final java.lang.String getWrapperKey()
Returns the wrapper key for the JSON content ornullfor none.- Since:
- 1.14
-
setWrapperKey
public JsonHttpContent setWrapperKey(java.lang.String wrapperKey)
Sets the wrapper key for the JSON content ornullfor none.Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
- Since:
- 1.14
-
-