Class XmlSerialiser

    • Method Detail

      • typeFromXml

        public static <T,​C> C typeFromXml​(Class<T> type,
                                                String source)
                                         throws JAXBException
        Convert a string to an object of a given class.
        Parameters:
        type - Type of object
        source - Input string
        Returns:
        Object of the given type
        Throws:
        JAXBException
      • typeFromXml

        public static <T,​C> C typeFromXml​(Class<T> type,
                                                File source)
                                         throws JAXBException
        Convert the contents of a file to an object of a given class.
        Parameters:
        type - Type of object
        source - File to be read
        Returns:
        Object of the given type
        Throws:
        JAXBException
      • typeFromXml

        public static <T,​C> C typeFromXml​(Class<T> type,
                                                Reader source)
                                         throws JAXBException
        Convert the contents of a Reader to an object of a given class.
        Parameters:
        type - Type of object
        source - Reader to be read
        Returns:
        Object of the given type
        Throws:
        JAXBException
      • typeFromXml

        public static <T,​C> C typeFromXml​(Class<T> type,
                                                InputStream source)
                                         throws JAXBException
        Convert the contents of an InputStream to an object of a given class.
        Parameters:
        type - Type of object
        source - InputStream to be read
        Returns:
        Object of the given type
        Throws:
        JAXBException
      • typeFromXml

        public static <T,​C> C typeFromXml​(Class<T> type,
                                                Source source)
                                         throws JAXBException
        Convert the contents of a Source to an object of a given class.
        Parameters:
        type - Type of object
        source - Source to be used
        Returns:
        Object of the given type
        Throws:
        JAXBException
      • collectionFromXml

        public static <T> List<T> collectionFromXml​(Class<T> type,
                                                    String source)
                                             throws JAXBException
        Converts the contents of the string to a List with objects of the given class.
        Parameters:
        type - Type to be used
        source - Input string
        Returns:
        List with objects of the given type
        Throws:
        JAXBException
      • collectionFromXml

        public static <T> List<T> collectionFromXml​(Class<T> type,
                                                    Reader source)
                                             throws JAXBException
        Converts the contents of the Reader to a List with objects of the given class.
        Parameters:
        type - Type to be used
        source - Input
        Returns:
        List with objects of the given type
        Throws:
        JAXBException
      • collectionFromXml

        public static <T> List<T> collectionFromXml​(Class<T> type,
                                                    InputStream source)
                                             throws JAXBException
        Converts the contents of the InputStream to a List with objects of the given class.
        Parameters:
        type - Type to be used
        source - Input
        Returns:
        List with objects of the given type
        Throws:
        JAXBException
      • collectionFromXml

        public static <T> List<T> collectionFromXml​(Class<T> type,
                                                    Source source)
                                             throws JAXBException
        Converts the contents of the Source to a List with objects of the given class.
        Parameters:
        type - Type to be used
        source - Input
        Returns:
        List with objects of the given type
        Throws:
        JAXBException
      • toXml

        public static <T> String toXml​(T obj,
                                       boolean format,
                                       boolean fragment)
                                throws JAXBException
        Convert an object to a string.
        Parameters:
        obj - Object that needs to be serialized / marshalled.
        Returns:
        String representation of obj
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(T obj,
                                     Writer wr,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert an object to a string and send it to a Writer.
        Parameters:
        obj - Object that needs to be serialized / marshalled
        wr - Writer used for outputting the marshalled object
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(T obj,
                                     XMLStreamWriter wr,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert an object to a string and send it to a Writer.
        Parameters:
        obj - Object that needs to be serialized / marshalled
        wr - Writer used for outputting the marshalled object
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(T obj,
                                     File f,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert an object to a string and save it to a File.
        Parameters:
        obj - Object that needs to be serialized / marshalled
        f - Save file
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(T obj,
                                     OutputStream source,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert an object to a string and send it to an OutputStream.
        Parameters:
        obj - Object that needs to be serialized / marshalled
        source - Stream used for output
        Throws:
        JAXBException
      • toXml

        public static <T> String toXml​(String rootName,
                                       Collection<T> c,
                                       boolean format,
                                       boolean fragment)
                                throws JAXBException
        Convert a collection to a string.
        Parameters:
        rootName - Name of the XML root element
        c - Collection that needs to be marshalled
        Returns:
        String representation of the collection
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(String rootName,
                                     Collection<T> c,
                                     Writer w,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert a collection to a string and sends it to the Writer.
        Parameters:
        rootName - Name of the XML root element
        c - Collection that needs to be marshalled
        w - Output
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(String rootName,
                                     Collection<T> c,
                                     File f,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert a collection to a string and stores it in a File.
        Parameters:
        rootName - Name of the XML root element
        c - Collection that needs to be marshalled
        f - Output file
        Throws:
        JAXBException
      • toXml

        public static <T> void toXml​(String rootName,
                                     Collection<T> c,
                                     OutputStream dest,
                                     boolean format,
                                     boolean fragment)
                              throws JAXBException
        Convert a collection to a string and sends it to the OutputStream.
        Parameters:
        rootName - Name of the XML root element
        c - Collection that needs to be marshalled
        dest - Output
        Throws:
        JAXBException
      • findTypes

        protected static <T> Class<?>[] findTypes​(Collection<T> c)
        Discovers all the classes in the given Collection. These need to be in the JAXBContext if you want to marshal those objects. Unfortunatly there's no way of getting the generic type at runtime.
        Parameters:
        c - Collection that needs to be scanned
        Returns:
        Classes found in the collection, including JAXBCollection.
      • createCollectionElement

        protected static <T> JAXBElement<?> createCollectionElement​(String rootName,
                                                                    Collection<T> c)
        Create a JAXBElement containing a JAXBCollection. Needed for marshalling a generic collection without a separate wrapper class.
        Parameters:
        rootName - Name of the XML root element
        c -
        Returns:
        JAXBElement containing the given Collection, wrapped in a JAXBCollection.