| Modifier and Type | Class and Description |
|---|---|
protected static class |
JaxbUtils.Cache
To improve the performance, we'll cache the last
JAXBContext used. |
| Modifier and Type | Field and Description |
|---|---|
protected static SoftReference<JaxbUtils.Cache> |
CACHE
Cache.
|
| Constructor and Description |
|---|
JaxbUtils() |
| Modifier and Type | Method and Description |
|---|---|
protected static <T> JAXBElement |
createCollectionElement(String rootName,
Collection<T> c)
Create a JAXBElement containing a JAXBCollection.
|
static XMLStreamReader |
createXmlStreamReader(InputStream is,
boolean namespaceAware)
Creates an XMLStreamReader based on an input stream.
|
static XMLStreamReader |
createXmlStreamReader(Path path,
boolean namespaceAware)
Creates an XMLStreamReader based on a file path.
|
static XMLStreamReader |
createXmlStreamReader(Reader reader,
boolean namespaceAware)
Creates an XMLStreamReader based on a Reader.
|
protected static <T> Class[] |
findTypes(Collection<T> c)
Discovers all the classes in the given Collection.
|
protected static XMLInputFactory |
getXmlInputFactory(boolean namespaceAware) |
static <T> String |
marshal(String rootName,
Collection<T> c)
Convert a collection to a string.
|
static <T> void |
marshal(String rootName,
Collection<T> c,
File f)
Convert a collection to a string and stores it in a File.
|
static <T> void |
marshal(String rootName,
Collection<T> c,
OutputStream s)
Convert a collection to a string and sends it to the
OutputStream.
|
static <T> void |
marshal(String rootName,
Collection<T> c,
Writer w)
Convert a collection to a string and sends it to the Writer.
|
static <T> String |
marshal(T obj)
Convert an object to a string.
|
static <T> void |
marshal(T obj,
File f)
Convert an object to a string and save it to a File.
|
static <T> void |
marshal(T obj,
OutputStream s)
Convert an object to a string and send it to an OutputStream.
|
static <T> void |
marshal(T obj,
Writer wr)
Convert an object to a string and send it to a Writer.
|
static <T> T |
unmarshal(Class<T> cl,
File f)
Convert the contents of a file to an object of a given class.
|
static <T> T |
unmarshal(Class<T> cl,
InputStream s)
Convert the contents of an InputStream to an object of a given
class.
|
static <T> T |
unmarshal(Class<T> cl,
Reader r)
Convert the contents of a Reader to an object of a given class.
|
static <T> T |
unmarshal(Class<T> cl,
Source s)
Convert the contents of a Source to an object of a given class.
|
static <T> T |
unmarshal(Class<T> cl,
String s)
Convert a string to an object of a given class.
|
static <T> List<T> |
unmarshalCollection(Class<T> cl,
InputStream s)
Converts the contents of the InputStream to a List with objects
of the given class.
|
static <T> List<T> |
unmarshalCollection(Class<T> cl,
Reader r)
Converts the contents of the Reader to a List with objects of
the given class.
|
static <T> List<T> |
unmarshalCollection(Class<T> cl,
Source s)
Converts the contents of the Source to a List with objects of
the given class.
|
static <T> List<T> |
unmarshalCollection(Class<T> cl,
String s)
Converts the contents of the string to a List with objects of
the given class.
|
static <T> T |
unmarshall(Class<T> clazz,
XMLStreamReader xsr) |
protected static volatile SoftReference<JaxbUtils.Cache> CACHE
JaxbUtils.Cache from being GC-ed,
hence SoftReference.public static XMLStreamReader createXmlStreamReader(Path path, boolean namespaceAware) throws JAXBException
path - the path to the file to be parsednamespaceAware - if false the XMLStreamReader will remove all namespaces from all XML elementsJAXBException - if the XMLStreamReader could not be createdpublic static XMLStreamReader createXmlStreamReader(InputStream is, boolean namespaceAware) throws JAXBException
is - the input stream from which the data to be parsed will be takennamespaceAware - if false the XMLStreamReader will remove all namespaces from all XML elementsJAXBException - if the XMLStreamReader could not be createdpublic static XMLStreamReader createXmlStreamReader(Reader reader, boolean namespaceAware) throws JAXBException
reader - Note that XMLStreamReader, despite the name, does not implement the Reader interface!namespaceAware - if false the XMLStreamReader will remove all namespaces from all XML elementsJAXBException - if the XMLStreamReader could not be createdprotected static XMLInputFactory getXmlInputFactory(boolean namespaceAware) throws JAXBException
JAXBExceptionpublic static <T> T unmarshall(Class<T> clazz, XMLStreamReader xsr) throws JAXBException
JAXBExceptionpublic static <T> T unmarshal(Class<T> cl, String s) throws JAXBException
cl - Type of objects - Input stringJAXBExceptionpublic static <T> T unmarshal(Class<T> cl, File f) throws JAXBException
cl - Type of objectf - File to be readJAXBExceptionpublic static <T> T unmarshal(Class<T> cl, Reader r) throws JAXBException
cl - Type of objectr - Reader to be readJAXBExceptionpublic static <T> T unmarshal(Class<T> cl, InputStream s) throws JAXBException
cl - Type of objects - InputStream to be readJAXBExceptionpublic static <T> T unmarshal(Class<T> cl, Source s) throws JAXBException
cl - Type of objects - Source to be usedJAXBExceptionpublic static <T> List<T> unmarshalCollection(Class<T> cl, String s) throws JAXBException
cl - Type to be useds - Input stringJAXBExceptionpublic static <T> List<T> unmarshalCollection(Class<T> cl, Reader r) throws JAXBException
cl - Type to be usedr - InputJAXBExceptionpublic static <T> List<T> unmarshalCollection(Class<T> cl, InputStream s) throws JAXBException
cl - Type to be useds - InputJAXBExceptionpublic static <T> List<T> unmarshalCollection(Class<T> cl, Source s) throws JAXBException
cl - Type to be useds - InputJAXBExceptionpublic static <T> String marshal(T obj) throws JAXBException
obj - Object that needs to be serialized / marshalled.JAXBExceptionpublic static <T> void marshal(T obj,
Writer wr)
throws JAXBException
obj - Object that needs to be serialized / marshalledwr - Writer used for outputting the marshalled objectJAXBExceptionpublic static <T> void marshal(T obj,
File f)
throws JAXBException
obj - Object that needs to be serialized / marshalledf - Save fileJAXBExceptionpublic static <T> void marshal(T obj,
OutputStream s)
throws JAXBException
obj - Object that needs to be serialized / marshalleds - Stream used for outputJAXBExceptionpublic static <T> String marshal(String rootName, Collection<T> c) throws JAXBException
rootName - Name of the XML root elementc - Collection that needs to be marshalledJAXBExceptionpublic static <T> void marshal(String rootName, Collection<T> c, Writer w) throws JAXBException
rootName - Name of the XML root elementc - Collection that needs to be marshalledw - OutputJAXBExceptionpublic static <T> void marshal(String rootName, Collection<T> c, File f) throws JAXBException
rootName - Name of the XML root elementc - Collection that needs to be marshalledf - Output fileJAXBExceptionpublic static <T> void marshal(String rootName, Collection<T> c, OutputStream s) throws JAXBException
rootName - Name of the XML root elementc - Collection that needs to be marshalleds - OutputJAXBExceptionprotected static <T> Class[] findTypes(Collection<T> c)
c - Collection that needs to be scannedprotected static <T> JAXBElement createCollectionElement(String rootName, Collection<T> c)
rootName - Name of the XML root elementc - Copyright © 2017. All rights reserved.