Class JsonHttpContent (1.43.0)

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.

Inheritance

Object > AbstractHttpContent > JsonHttpContent

Constructors

JsonHttpContent(JsonFactory jsonFactory, Object data)

public JsonHttpContent(JsonFactory jsonFactory, Object data)
Parameters
NameDescription
jsonFactoryJsonFactory

JSON factory to use

dataObject

JSON key name/value data

Methods

getData()

public final Object getData()

Returns the JSON key name/value data.

Returns
TypeDescription
Object

getJsonFactory()

public final JsonFactory getJsonFactory()

Returns the JSON factory.

Returns
TypeDescription
JsonFactory

getWrapperKey()

public final String getWrapperKey()

Returns the wrapper key for the JSON content or null for none.

Returns
TypeDescription
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.

Parameter
NameDescription
mediaTypeHttpMediaType
Returns
TypeDescription
JsonHttpContent
Overrides

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.

Parameter
NameDescription
wrapperKeyString
Returns
TypeDescription
JsonHttpContent

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
NameDescription
outOutputStream
Exceptions
TypeDescription
IOException