Class MarshallingUtil
- java.lang.Object
-
- hu.icellmobilsoft.coffee.tool.utils.marshalling.MarshallingUtil
-
public class MarshallingUtil extends Object
Utility methods for marshalling.- Since:
- 1.0.0
- Author:
- karcsi
-
-
Constructor Summary
Constructors Constructor Description MarshallingUtil()Default constructor, constructs a new object.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidfillOptionalField(T lhs, jakarta.xml.bind.JAXBElement<T> rhs, Consumer<T> setter)Set the value of the database field if it is necessary.static Stringmarshall(Object object)Marshals an object to aStringxml.static voidmarshall(Object object, OutputStream s)Marshals an object to a stream.static <T> voidmarshall(Object object, OutputStream s, Class<T> c)Marshals an object to a stream.static StringmarshallUncheckedXml(Object object)Marshals an object to aStringxml.static StringmarshallUncheckedXml(Object object, jakarta.xml.bind.Marshaller m)Marshals an object to aStringxml.static voidmarshallUncheckedXml(Object object, OutputStream s)Marshals an object to a stream.static <T> voidmarshallUncheckedXml(Object object, OutputStream s, Class<T> c)Marshals an object to a stream.static <T> StringmarshallUncheckedXml(Object object, Class<T> c)Marshals an object to aStringxml.static <T> Tunmarshall(String str, Class<T> c)Unmarshalls an object from aString.static <T> TunmarshallUncheckedXml(String str, Class<T> c)Unmarshalls an object from an xmlString.
-
-
-
Method Detail
-
marshall
public static String marshall(Object object)
Marshals an object to aStringxml.- Parameters:
object- source object- Returns:
- marshalled xml
Stringor null if marshalling error
-
marshallUncheckedXml
public static String marshallUncheckedXml(Object object) throws jakarta.xml.bind.JAXBException
Marshals an object to aStringxml.- Parameters:
object- source object- Returns:
- marshalled xml
Stringor null if invalid input - Throws:
jakarta.xml.bind.JAXBException- on marshalling exception
-
marshallUncheckedXml
public static <T> String marshallUncheckedXml(Object object, Class<T> c) throws jakarta.xml.bind.JAXBException
Marshals an object to aStringxml.- Type Parameters:
T- object type- Parameters:
object- source objectc- object class- Returns:
- marshalled xml
Stringor null if invalid input - Throws:
jakarta.xml.bind.JAXBException- if marshalling error
-
marshallUncheckedXml
public static String marshallUncheckedXml(Object object, jakarta.xml.bind.Marshaller m) throws jakarta.xml.bind.JAXBException
Marshals an object to aStringxml.- Parameters:
object- source objectm- marshaller- Returns:
- marshalled xml
Stringor null if invalid input - Throws:
jakarta.xml.bind.JAXBException- if marshalling error
-
marshall
public static void marshall(Object object, OutputStream s)
Marshals an object to a stream.- Parameters:
object- source objects- output stream
-
marshall
public static <T> void marshall(Object object, OutputStream s, Class<T> c)
Marshals an object to a stream.- Type Parameters:
T- object type- Parameters:
object- source objects- output streamc- object class
-
marshallUncheckedXml
public static void marshallUncheckedXml(Object object, OutputStream s) throws jakarta.xml.bind.JAXBException
Marshals an object to a stream.- Parameters:
object- source objects- output stream- Throws:
jakarta.xml.bind.JAXBException- if marshalling error
-
marshallUncheckedXml
public static <T> void marshallUncheckedXml(Object object, OutputStream s, Class<T> c) throws jakarta.xml.bind.JAXBException
Marshals an object to a stream.- Type Parameters:
T- object type- Parameters:
object- source objects- output streamc- object class- Throws:
jakarta.xml.bind.JAXBException- if marshalling error
-
unmarshall
public static <T> T unmarshall(String str, Class<T> c)
Unmarshalls an object from aString.- Type Parameters:
T- object type- Parameters:
str-Stringsourcec- object class- Returns:
- unmarshalled dto object or null if unmarshalling error
-
unmarshallUncheckedXml
public static <T> T unmarshallUncheckedXml(String str, Class<T> c)
Unmarshalls an object from an xmlString.- Type Parameters:
T- object type- Parameters:
str-Stringsourcec- object class- Returns:
- unmarshalled dto object or null if invalid input or unmarshalling error
-
fillOptionalField
public static <T> void fillOptionalField(T lhs, jakarta.xml.bind.JAXBElement<T> rhs, Consumer<T> setter)Set the value of the database field if it is necessary.- Type Parameters:
T- dto object type- Parameters:
lhs- left hand side of the assign (the dto object)rhs- right hand side of the assign (the input value)setter- the setter method of the right hand side field (the dto setter)
-
-