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
|
| 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
Sets the media type to use for the Content-Type header, or
null if unspecified.
|
JsonHttpContent |
setWrapperKey(String
Sets the wrapper key for the JSON content or
null for none.
|
void |
writeTo(OutputStream
Writes the byte content to the given output stream.
|
computeLength, computeLength, getCharset, getLength, getMediaType, getType, retrySupportedpublic JsonHttpContent(JsonFactoryjsonFactory, Object data)
jsonFactory - JSON factory to use
data - JSON key name/value data
public void writeTo(OutputStreamout) throws IOException
StreamingContent
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.
out - output stream
IOException
public JsonHttpContentsetMediaType(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.
public final ObjectgetData()
public final JsonFactorygetJsonFactory()
public final StringgetWrapperKey()
null for none.
public JsonHttpContentsetWrapperKey(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.