Class JsonHttpContent

java.lang.Object
com.google.api.client.http.AbstractHttpContent
com.google.api.client.http.json.JsonHttpContent
All Implemented Interfaces:
HttpContent, StreamingContent

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.

Since:
1.0
  • Field Details

    • data

      private final Object data
      JSON key name/value data.
    • jsonFactory

      private final JsonFactory jsonFactory
      JSON factory.
    • wrapperKey

      private String wrapperKey
      Wrapper key for the JSON content or null for none.
  • Constructor Details

    • JsonHttpContent

      public JsonHttpContent(JsonFactory jsonFactory, Object data)
      Parameters:
      jsonFactory - JSON factory to use
      data - JSON key name/value data
      Since:
      1.5
  • Method Details

    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Description copied from interface: StreamingContent
      Writes the byte content to the given output stream.

      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.

      Parameters:
      out - output stream
      Throws:
      IOException
    • setMediaType

      public JsonHttpContent setMediaType(HttpMediaType mediaType)
      Description copied from class: AbstractHttpContent
      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.

      Overrides:
      setMediaType in class AbstractHttpContent
    • getData

      public final Object getData()
      Returns the JSON key name/value data.
      Since:
      1.5
    • getJsonFactory

      public final JsonFactory getJsonFactory()
      Returns the JSON factory.
      Since:
      1.5
    • getWrapperKey

      public final String getWrapperKey()
      Returns the wrapper key for the JSON content or null for none.
      Since:
      1.14
    • setWrapperKey

      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.

      Since:
      1.14