Class MarshallingUtil


  • public class MarshallingUtil
    extends Object
    Utility methods for marshalling.
    Since:
    1.0.0
    Author:
    karcsi
    • Constructor Detail

      • MarshallingUtil

        public MarshallingUtil()
        Default constructor, constructs a new object.
    • Method Detail

      • marshall

        public static String marshall​(Object object)
        Marshals an object to a String xml.
        Parameters:
        object - source object
        Returns:
        marshalled xml String or null if marshalling error
      • marshallUncheckedXml

        public static String marshallUncheckedXml​(Object object)
                                           throws jakarta.xml.bind.JAXBException
        Marshals an object to a String xml.
        Parameters:
        object - source object
        Returns:
        marshalled xml String or 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 a String xml.
        Type Parameters:
        T - object type
        Parameters:
        object - source object
        c - object class
        Returns:
        marshalled xml String or 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 a String xml.
        Parameters:
        object - source object
        m - marshaller
        Returns:
        marshalled xml String or 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 object
        s - 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 object
        s - output stream
        c - 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 object
        s - 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 object
        s - output stream
        c - 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 a String.
        Type Parameters:
        T - object type
        Parameters:
        str - String source
        c - 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 xml String.
        Type Parameters:
        T - object type
        Parameters:
        str - String source
        c - 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)