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.
Constructors
JsonHttpContent(JsonFactory jsonFactory, Object data)
public JsonHttpContent(JsonFactory jsonFactory, Object data)
Name | Description |
jsonFactory | JsonFactory JSON factory to use |
data | Object JSON key name/value data |
Methods
getData()
public final Object getData()
Returns the JSON key name/value data.
Type | Description |
Object |
getJsonFactory()
public final JsonFactory getJsonFactory()
Returns the JSON factory.
Type | Description |
JsonFactory |
getWrapperKey()
public final String getWrapperKey()
Returns the wrapper key for the JSON content or null
for none.
Type | Description |
String |
setMediaType(HttpMediaType mediaType)
public JsonHttpContent setMediaType(HttpMediaType mediaType)
Sets the media type to use for the Content-Type header, or 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.
Name | Description |
mediaType | HttpMediaType |
Type | Description |
JsonHttpContent |
setWrapperKey(String wrapperKey)
public JsonHttpContent setWrapperKey(String wrapperKey)
Sets the wrapper key for the JSON content or null
for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
Name | Description |
wrapperKey | String |
Type | Description |
JsonHttpContent |
writeTo(OutputStream out)
public void writeTo(OutputStream out)
Name | Description |
out | OutputStream |
Type | Description |
IOException |