Interface Marshaller<T>

All Known Implementing Classes:
AbstractMarshaller, BinaryMarshaller, JacksonJsonMarshaller, JaxbXmlMarshaller, JsonJacksonMarshaller, KeyConverterAdapter, StaticContentMarshaller, StringMarshaller, XmlJaxbMarshaller

public interface Marshaller<T>
An interface that must be implemented by REST marshallers.
Author:
as 2011.07.10
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the system property that is used to determine whether the marshaller output should be formatted for human readability.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    marshal(T value, OutputStream out, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
    Write the specified object into the given stream.
    default void
    marshalAsFragment(T value, OutputStream out, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
    Write the specified object into the given stream as a fragment.
    unmarshal(InputStream in, jakarta.ws.rs.core.MediaType mediaType)
    Read an object from the specified stream.
  • Field Details

    • FORMAT_OUTPUT

      static final String FORMAT_OUTPUT
      The name of the system property that is used to determine whether the marshaller output should be formatted for human readability.
      See Also:
  • Method Details

    • marshal

      void marshal(T value, OutputStream out, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
      Write the specified object into the given stream.
      Parameters:
      value - object to marshall
      out - the OutputStream for the HTTP entity. The implementation should not close the output stream.
      httpHeaders - a mutable map of the HTTP message headers.
      Throws:
      IOException - if an error occurs during marshalling
    • marshalAsFragment

      default void marshalAsFragment(T value, OutputStream out, jakarta.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
      Write the specified object into the given stream as a fragment.

      This method is called when marshalling collections of objects, as marshalling behavior might differ when an object is serialized directly or as element of a collection.

      For example, when marshalling a collection of objects into XML, you need to ensure that the XML declaration is emmitted only once, not for each object in the collection.

      In cases where there is no difference in output between fragments and full objects (JSON, for example), this method could simply delegate to marshal(Object, OutputStream, MultivaluedMap).

      Parameters:
      value - object to marshall
      out - the OutputStream for the HTTP entity. The implementation should not close the output stream.
      httpHeaders - a mutable map of the HTTP message headers.
      Throws:
      IOException - if an error occurs during marshalling
    • unmarshal

      T unmarshal(InputStream in, jakarta.ws.rs.core.MediaType mediaType) throws IOException
      Read an object from the specified stream.
      Parameters:
      in - stream to read from
      mediaType - the media type of the object to read
      Returns:
      unmarshalled object instance
      Throws:
      IOException - if an error occurs during unmarshalling