Interface Marshaller<T>

    • Field Detail

      • 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:
        Constant Field Values
    • Method Detail

      • marshal

        void marshal​(T value,
                     OutputStream out,
                     javax.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,
                                       javax.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,
                    javax.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