Class JAXBSerialiser
This helper also translates the exceptions that can be thrown during a JAXB serialise/deserialise operation in a
JAXBRuntimeException- 
Method SummaryModifier and TypeMethodDescriptiondeserialise(File file) Deserialise a File of XML to an Object (or JAXBElement)Deserialise a stream of XML to an Object (or JAXBElement)<T> Tdeserialise(Class<T> clazz, String xml) Deserialise and cast to a particular type<T> Tdeserialise(Class<T> clazz, Element xml) Deserialise and cast to a particular type<T> Tdeserialise(Class<T> clazz, InputSource source) Deserialise an input and cast to a particular typedeserialise(String xml) Deserialise a String of XML to an Object (or JAXBElement)deserialise(XMLStreamReader reader) Deserialise an XMLStreamReader to an Object (or JAXBElement)deserialise(Node node) Deserialise a DOM Node to an Object (or JAXBElement)deserialise(InputSource source) javax.xml.bind.JAXBContextRetrieve the inner JAXBContext
 NOTE: use of this method is strongly discouraged!static JAXBSerialisergetInstance(Class<?>... classes) Helper method to get a JAXBSerialiser for a set of classes with the underlying JAXB implementation picked using the default rules for JAXB acquisition
 This is an expensive operation and so the result should ideally be cachedstatic JAXBSerialisergetInstance(String contextPath) Helper method to get a JAXBSerialiser from a JAXB Context Path (i.e.static JAXBSerialisergetInstance(javax.xml.bind.JAXBContext context) Helper method to get a JAXBSerialiser from an existing JAXBContext.
 This is an expensive operation and so the result should ideally be cachedstatic JAXBSerialiserHelper method to get a JAXBSerialiser that uses EclipseLink MOXy for all operationsstatic JAXBSerialiserHelper method to get a JAXBSerialiser that uses EclipseLink MOXy for all operationsstatic voidHelper method to print a serialised object to stdout (for dev/debugging use)voidvoidserialise(Object obj, OutputStream os) voidvoidserialise(Object obj, XMLStreamWriter writer) Marshals the provided type to the given XMLStreamWriter, filtering the XML stream to remove duplicate xmlns="" events if present.voidHelper method to serialise an Object to an org.w3c.dom.DocumentvoidserialiseWithDirectWriter(Object obj, XMLStreamWriter writer) Marshals the provided type directly to the provided XMLStreamWriter.setEncoding(String encoding) Specify an output encoding to use when marshalling the XML data.setFragment(boolean fragment) Specify the value of jaxb.fragment used by the underlying marshallersetNoNamespaceSchemaLocation(String noNamespaceSchemaLocation) Specify an xsi:noNamespaceSchemaLocation in the generated XMLsetPrettyOutput(boolean pretty) Enable/Disable pretty printingOptionally specify the schema to use for all future serialisation/deserialisation methodssetSchemaLocation(String schemaLocation) Specify an xsi:schemaLocation attribute in the generated XML
- 
Method Details- 
getContextpublic javax.xml.bind.JAXBContext getContext()Retrieve the inner JAXBContext
 NOTE: use of this method is strongly discouraged!- Returns:
 
- 
setSchemaOptionally specify the schema to use for all future serialisation/deserialisation methodsNote that if this serializer is returned from and cached by a JAXBSerialiserFactorythen use of this method could result in unintended side effects for other classes sharing the JAXBSerialiserFactory- Parameters:
- schema-
- Returns:
- this for method chaining
 
- 
setPrettyOutputEnable/Disable pretty printing- Parameters:
- pretty-
- Returns:
- this for method chaining
 
- 
setEncodingSpecify an output encoding to use when marshalling the XML data. The default is UTF-8Note that if this serializer is returned from and cached by a JAXBSerialiserFactorythen use of this method could result in unintended side effects for other classes sharing the JAXBSerialiserFactory- Parameters:
- encoding-
- Returns:
- this for method chaining
 
- 
setSchemaLocationSpecify an xsi:schemaLocation attribute in the generated XMLNote that if this serializer is returned from and cached by a JAXBSerialiserFactorythen use of this method could result in unintended side effects for other classes sharing the JAXBSerialiserFactory- Parameters:
- schemaLocation-
- Returns:
- this for method chaining
 
- 
setNoNamespaceSchemaLocationSpecify an xsi:noNamespaceSchemaLocation in the generated XMLNote that if this serializer is returned from and cached by a JAXBSerialiserFactorythen use of this method could result in unintended side effects for other classes sharing the JAXBSerialiserFactory- Parameters:
- noNamespaceSchemaLocation-
- Returns:
- this for method chaining
 
- 
setFragmentSpecify the value of jaxb.fragment used by the underlying marshallerNote that if this serializer is returned from and cached by a JAXBSerialiserFactorythen use of this method could result in unintended side effects for other classes sharing the JAXBSerialiserFactory- Parameters:
- fragment-
- Returns:
- this for method chaining
- See Also:
- 
- Marshaller
 
 
- 
deserialiseDeserialise a String of XML to an Object (or JAXBElement)- Parameters:
- xml-
- Returns:
 
- 
deserialiseDeserialise a stream of XML to an Object (or JAXBElement)- Parameters:
- is-
- Returns:
 
- 
deserialiseDeserialise an input and cast to a particular type- Parameters:
- clazz-
- source-
- Returns:
 
- 
deserialiseDeserialise and cast to a particular type- Parameters:
- clazz-
- xml- a String of XML
- Returns:
 
- 
deserialiseDeserialise and cast to a particular type- Parameters:
- clazz-
- xml- an XML element
- Returns:
 
- 
deserialiseDeserialise a File of XML to an Object (or JAXBElement)- Parameters:
- file-
- Returns:
 
- 
deserialise
- 
deserialiseDeserialise an XMLStreamReader to an Object (or JAXBElement)- Parameters:
- reader-
- Returns:
 
- 
deserialiseDeserialise a DOM Node to an Object (or JAXBElement)- Parameters:
- node-
- Returns:
 
- 
serialiseToDocumentHelper method to serialise an Object to an org.w3c.dom.Document- Parameters:
- obj- the object to serialise
- Returns:
- a new Document containing the serialised form of the provided Object
 
- 
serialise
- 
serialise
- 
serialise
- 
serialise
- 
serialiseWithDirectWriterMarshals the provided type directly to the provided XMLStreamWriter. This is provided to allow callers to bypass the EclipseLink MOXy mitigation against XmlAnyElements which contain xmlns=""- Parameters:
- obj-
- writer-
 
- 
serialiseMarshals the provided type to the given XMLStreamWriter, filtering the XML stream to remove duplicate xmlns="" events if present. This is to work around an EclipseLink MOXy issue whereby XmlAnyElements which contain xmlns="" get that namespace definition duplicated via STaX- Parameters:
- obj-
- writer-
 
- 
printHelper method to print a serialised object to stdout (for dev/debugging use)- Parameters:
- obj-
 
- 
serialise
- 
getInstanceHelper method to get a JAXBSerialiser from an existing JAXBContext.
 This is an expensive operation and so the result should ideally be cached- Parameters:
- context- an existing JAXBContext
- Returns:
 
- 
getInstanceHelper method to get a JAXBSerialiser for a set of classes with the underlying JAXB implementation picked using the default rules for JAXB acquisition
 This is an expensive operation and so the result should ideally be cached- Parameters:
- classes-
- Returns:
 
- 
getInstanceHelper method to get a JAXBSerialiser from a JAXB Context Path (i.e. a package name or colon-delimited list of package names) with the underlying JAXB implementation picked using the default rules for JAXB acquisition
 This is an expensive operation and so the result should ideally be cached- Parameters:
- contextPath- a package name or colon-delimited list of package names
- Returns:
 
- 
getMoxyHelper method to get a JAXBSerialiser that uses EclipseLink MOXy for all operations- Parameters:
- contextPath-
- Returns:
 
- 
getMoxyHelper method to get a JAXBSerialiser that uses EclipseLink MOXy for all operations- Parameters:
- classes-
- Returns:
 
 
-