Class JsonHttpContent
java.lang.Object
com.google.api.client.http.AbstractHttpContent
com.google.api.client.http.json.JsonHttpContent
- All Implemented Interfaces:
HttpContent, StreamingContent
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
FieldsModifier and TypeFieldDescriptionprivate final ObjectJSON key name/value data.private final JsonFactoryJSON factory.private StringWrapper key for the JSON content ornullfor none. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ObjectgetData()Returns the JSON key name/value data.final JsonFactoryReturns the JSON factory.final StringReturns the wrapper key for the JSON content ornullfor none.setMediaType(HttpMediaType mediaType) Sets the media type to use for the Content-Type header, ornullif unspecified.setWrapperKey(String wrapperKey) Sets the wrapper key for the JSON content ornullfor none.voidwriteTo(OutputStream out) Writes the byte content to the given output stream.Methods inherited from class AbstractHttpContent
computeLength, computeLength, getCharset, getLength, getMediaType, getType, retrySupported
-
Field Details
-
data
JSON key name/value data. -
jsonFactory
JSON factory. -
wrapperKey
Wrapper key for the JSON content ornullfor none.
-
-
Constructor Details
-
JsonHttpContent
- Parameters:
jsonFactory- JSON factory to usedata- JSON key name/value data- Since:
- 1.5
-
-
Method Details
-
writeTo
Description 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 output stream has not been closed, and will fail to work if it has been closed.
- Parameters:
out- output stream- Throws:
IOException
-
setMediaType
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
-
getJsonFactory
-
getWrapperKey
Returns the wrapper key for the JSON content ornullfor none.- Since:
- 1.14
-
setWrapperKey
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
-