public class JaxbXmlMarshaller extends AbstractMarshaller
FORMAT_OUTPUT
Constructor and Description |
---|
JaxbXmlMarshaller(Class 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(Object oValue, OutputStream out)
Write the specified object into the given stream.
|
void |
marshalAsFragment(Object oValue, OutputStream out)
Write the specified object into the given stream as a fragment.
|
Object |
unmarshal(InputStream in)
Read an object from the specified stream.
|
getRootClass
public JaxbXmlMarshaller(Class clzRoot)
clzRoot
- class of the root object this marshaller is forpublic void marshal(Object oValue, OutputStream out) throws IOException
oValue
- object to marshallout
- stream to write toIOException
- if an error occurs during marshallingpublic void marshalAsFragment(Object oValue, OutputStream out) 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 Marshaller.marshal(Object, OutputStream)
.
marshalAsFragment
in interface Marshaller
marshalAsFragment
in class AbstractMarshaller
oValue
- object to marshallout
- stream to write toIOException
- if an error occurs during marshallingpublic Object unmarshal(InputStream in) throws IOException
in
- stream to read fromIOException
- 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