Class XMLFile

java.lang.Object
net.hironico.common.utils.XMLFile

public class XMLFile extends Object
Utility class for XML serialization and deserialization using Jackson XmlMapper.
  • Constructor Details

    • XMLFile

      public XMLFile()
  • Method Details

    • serialize

      public static String serialize(Object obj) throws IOException
      Serializes an object to XML string.
      Parameters:
      obj - the object to serialize
      Returns:
      the XML string representation
      Throws:
      IOException - if serialization fails
    • saveAs

      public static void saveAs(File file, Object obj) throws IOException
      Saves an object to a file in XML format.
      Parameters:
      file - the file to save to
      obj - the object to serialize
      Throws:
      IOException - if writing fails
    • load

      public static <T> T load(InputStream in, Class<T> clazz) throws IOException
      Loads an object from XML input stream.
      Type Parameters:
      T - the type
      Parameters:
      in - the input stream containing XML
      clazz - the class to deserialize to
      Returns:
      the deserialized object
      Throws:
      IOException - if reading fails
    • load

      public static <T> T load(File file, Class<T> clazz) throws IOException
      Loads an object from XML file.
      Type Parameters:
      T - the type
      Parameters:
      file - the file containing XML
      clazz - the class to deserialize to
      Returns:
      the deserialized object
      Throws:
      IOException - if reading fails