Class JaxbExtensions
- java.lang.Object
-
- org.apache.groovy.jaxb.extensions.JaxbExtensions
-
public class JaxbExtensions extends Object
This class defines new groovy methods which appear on Jaxb-related JDK classes (JAXBContext
,Marshaller
) inside the Groovy environment. Static methods are used with the first parameter being the destination class.
-
-
Constructor Summary
Constructors Constructor Description JaxbExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> String
marshal(JAXBContext self, T jaxbElement)
Marshall an object to a xmlString
.static <T> String
marshal(Marshaller self, T jaxbElement)
Marshall an object to a xmlString
.static <T> T
unmarshal(JAXBContext self, String xml, Class<T> declaredType)
Unmarshal xml data from the givenString
to object of the given type.static <T> T
unmarshal(Unmarshaller self, String xml, Class<T> declaredType)
Unmarshal xml data from the givenString
to object of the given type.
-
-
-
Method Detail
-
marshal
public static <T> String marshal(Marshaller self, T jaxbElement) throws JAXBException
Marshall an object to a xmlString
.- Parameters:
self
- a Marshaller which can marshall the type of the given objectjaxbElement
- object to marshall to aString
- Returns:
String
representing the object as xml- Throws:
JAXBException
-
marshal
public static <T> String marshal(JAXBContext self, T jaxbElement) throws JAXBException
Marshall an object to a xmlString
.- Parameters:
self
- a JaxbContext, which recognizes the type of the given objectjaxbElement
- object to marshall to aString
- Returns:
- String representing the object as xml
- Throws:
JAXBException
-
unmarshal
public static <T> T unmarshal(Unmarshaller self, String xml, Class<T> declaredType) throws JAXBException
Unmarshal xml data from the givenString
to object of the given type.- Parameters:
self
- Unmarshaller, a Unmarshaller which can unmarshall the type of the given objectxml
- xml data as aString
declaredType
- appropriate JAXB mapped class to hold node's xml data- Returns:
- instance of destination class unmarshalled from xml
- Throws:
JAXBException
-
unmarshal
public static <T> T unmarshal(JAXBContext self, String xml, Class<T> declaredType) throws JAXBException
Unmarshal xml data from the givenString
to object of the given type.- Parameters:
self
- a JaxbContext, which recognizes the type of the given objectxml
- xml data as aString
declaredType
- appropriate JAXB mapped class to hold node's xml data- Returns:
- instance of destination class unmarshalled from xml
- Throws:
JAXBException
-
-