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.
|
String |
getWrapperKey()
Returns the wrapper key for the JSON content or
null for none. |
JsonHttpContent |
setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or
null if unspecified. |
JsonHttpContent |
setWrapperKey(String wrapperKey)
Sets the wrapper key for the JSON content or
null for none. |
void |
writeTo(OutputStream out)
Writes the byte content to the given output stream.
|
computeLength, computeLength, getCharset, 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
StreamingContent
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.
out
- output streamIOException
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()
public final String getWrapperKey()
null
for none.public JsonHttpContent setWrapperKey(String wrapperKey)
null
for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
Copyright © 2011–2022 Google. All rights reserved.