public class JaxbXmlMarshaller<T> extends AbstractMarshaller<T>
FORMAT_OUTPUT
Constructor and Description |
---|
JaxbXmlMarshaller(Class<T> clzRoot)
Construct an JaxbXmlMarshaller instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
configureJaxbMarshaller(Marshaller marshaller)
Configure a JAXB marshaller.
|
protected void |
configureJaxbUnmarshaller(Unmarshaller unmarshaller)
Configure a JAXB unmarshaller.
|
void |
marshal(T value,
OutputStream out,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
Write the specified object into the given stream.
|
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.
|
getRootClass
public void marshal(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
Marshaller
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 marshallingpublic void marshalAsFragment(T value, OutputStream out, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders) throws IOException
Marshaller
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 Marshaller.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 marshallingpublic T unmarshal(InputStream in, javax.ws.rs.core.MediaType mediaType) throws IOException
Marshaller
in
- stream to read frommediaType
- the media type of the object to readIOException
- if an error occurs during unmarshallingprotected void configureJaxbMarshaller(Marshaller marshaller) throws PropertyException
marshaller
- marshaller to configurePropertyException
- when there is an error processing a property
or valueprotected void configureJaxbUnmarshaller(Unmarshaller unmarshaller) throws PropertyException
unmarshaller
- unmarshaller to configurePropertyException
- when there is an error processing a property
or value