Package com.mooltiverse.oss.nyx.data
Class FileMapper
- java.lang.Object
-
- com.mooltiverse.oss.nyx.data.FileMapper
-
public class FileMapper extends Object
This class is used to load and save data files like configuration or state files.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
load(File file, Class<T> type)
Unmarshals the content of the given file to an object of the given type.static void
save(String filePath, Object content)
Marshals the content of the given object to a file represented by the given path
-
-
-
Method Detail
-
load
public static <T> T load(File file, Class<T> type) throws DataAccessException
Unmarshals the content of the given file to an object of the given type.- Type Parameters:
T
- the type of object to unmarshal.- Parameters:
file
- the file to load from. The file path must end with one of the supported extensions:json
,yaml
,properties
type
- the class representing the type of object to unmarshal.- Returns:
- the object instance unmarshalled from the given file.
- Throws:
DataAccessException
- in case of any exception due to data accessIllegalArgumentException
- if the given file path does not contain a supported extension
-
save
public static void save(String filePath, Object content) throws DataAccessException
Marshals the content of the given object to a file represented by the given path- Parameters:
filePath
- the path of the file to save to. If it's a relative path it will be considered relative to the current working directory. The file path must end with one of the supported extensions:json
,yaml
,properties
content
- the object to marshal.- Throws:
DataAccessException
- in case of any exception due to data accessIllegalArgumentException
- if the given file path does not contain a supported extension
-
-