File
The File class provides methods to save and load objects to and from files in JSON or XML format. It supports saving and loading objects with automatic detection of file type based on the method used. The class uses Jackson ObjectMapper for JSON and XmlMapper for XML serialization and deserialization.
Usage examples:
// Save an object as JSON
File.save("/path/to/file.json", myObject);
// Save an object as XML
File.saveXML("/path/to/file.xml", myObject);
// Load an object from JSON
MyClass obj = File.load("/path/to/file.json", MyClass.class);
// Load an object from XML
MyClass obj = File.loadXML("/path/to/file.xml", MyClass.class);
Note: The file paths can be absolute or relative. If a relative path is provided, the class will attempt to load the file from the classpath.
Supported file types:
- JSON
- XML
