Class XmlUnmarshaller

java.lang.Object
org.projecthusky.common.utils.xml.XmlUnmarshaller

@DefaultQualifier(value=org.checkerframework.checker.nullness.qual.NonNull.class, locations={PARAMETER,RETURN}) public class XmlUnmarshaller extends Object
This class provides an unmarshaller implementation to read various objects from their XML representation.
Author:
Quentin Ligier
  • Method Details

    • unmarshallStringAsType

      public static <T> T unmarshallStringAsType(String xmlContent, Class<T> returnType) throws javax.xml.bind.DataBindingException, ParserConfigurationException
      Unmarshalles an object of type <T> from its XML representation given as a string.
      Type Parameters:
      T - The type of object to unmarshall.
      Parameters:
      xmlContent - The XML content.
      returnType - The type of object to unmarshall.
      Returns:
      an object of type <T>.
      Throws:
      javax.xml.bind.DataBindingException - if the unmarshalling fails because of the content.
      ParserConfigurationException - if the unmarshalling fails because of the parser.
    • unmarshallFileAsType

      public static <T> T unmarshallFileAsType(File xmlFile, Class<T> returnType) throws javax.xml.bind.DataBindingException, IOException, ParserConfigurationException
      Unmarshalles an object of type <T> from an XML file.
      Type Parameters:
      T - The type of object to unmarshall.
      Parameters:
      xmlFile - The XML file.
      returnType - The type of object to unmarshall.
      Returns:
      an object of type <T>.
      Throws:
      javax.xml.bind.DataBindingException - if the unmarshalling fails because of the content.
      ParserConfigurationException - if the unmarshalling fails because of the parser.
      FileNotFoundException - if the file does not exist.
      IOException - if an I/O error occurs.
    • unmarshallAsType

      public static <T> T unmarshallAsType(InputSource inputSource, Class<T> returnType) throws javax.xml.bind.DataBindingException, ParserConfigurationException
      Unmarshalles an object of type <T> from a InputSource.
      Type Parameters:
      T - The type of object to unmarshall.
      Parameters:
      inputSource - The source of the XML representation to unmarshall.
      returnType - The type of object to unmarshall.
      Returns:
      an object of type <T>.
      Throws:
      javax.xml.bind.DataBindingException - if the unmarshalling fails because of the content.
      ParserConfigurationException - if the unmarshalling fails because of the parser.