public interface Marshaller<T>
Modifier and Type | Field and Description |
---|---|
static String |
FORMAT_OUTPUT
The name of the system property that is used to determine whether the marshaller output should be formatted for human readability.
|
Modifier and Type | Method and Description |
---|---|
void |
marshal(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
Write the specified object into the given stream.
|
default void |
marshalAsFragment(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
Write the specified object into the given stream as a fragment.
|
T |
unmarshal(InputStream in, javax.ws.rs.core.MediaType mediaType)
Read an object from the specified stream.
|
static final String FORMAT_OUTPUT
void marshal(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
value
- object to marshallout
- the OutputStream
for the HTTP entity. The implementation should not close the output stream.httpHeaders
- a mutable map of the HTTP message headers.IOException
- if an error occurs during marshallingdefault void marshalAsFragment(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
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)
.
value
- object to marshallout
- the OutputStream
for the HTTP entity. The implementation should not close the output stream.httpHeaders
- a mutable map of the HTTP message headers.IOException
- if an error occurs during marshallingT unmarshal(InputStream in, javax.ws.rs.core.MediaType mediaType) throws IOException
in
- stream to read frommediaType
- the media type of the object to readIOException
- if an error occurs during unmarshalling