Class JsonHttpContent (1.43.2)

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

Returns
Type Description
Object

getJsonFactory()

public final JsonFactory getJsonFactory()

Returns the JSON factory.

Returns
Type Description
JsonFactory

getWrapperKey()

public final String getWrapperKey()

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

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

Parameter
Name Description
mediaType HttpMediaType
Returns
Type Description
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
Name Description
wrapperKey String
Returns
Type Description
JsonHttpContent

writeTo(OutputStream out)

public void writeTo(OutputStream out)
Parameter
Name Description
out OutputStream
Exceptions
Type Description
IOException