Package dev.selena.luacore.utils.config
Class ConfigLoader
java.lang.Object
dev.selena.luacore.utils.config.ConfigLoader
Config loader used to load and save json config files
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
loadConfig
(Class<T> cls, File file) Loads a provided config object from a given JSON file.static void
saveConfig
(Object config, File file) Saves a config object to the specified file in JSON format
-
Constructor Details
-
ConfigLoader
public ConfigLoader()
-
-
Method Details
-
loadConfig
public static <T> T loadConfig(Class<T> cls, File file) throws IOException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException Loads a provided config object from a given JSON file. If the file does not exist it also creates the file using the given object defaults- Type Parameters:
T
- The class type you want to map to- Parameters:
cls
- The object type you wish to load, also dictates the class of the returned objectfile
- The file that is to be created/read from- Returns:
- The object loaded from file
- Throws:
IOException
- Thrown when the file can not be foundInstantiationException
- Throwing when the class has an initialization issueIllegalAccessException
- Thrown when trying to access a field without the correct access levelInvocationTargetException
- Thrown when the mapper class has a constructor that does not match the arguments (There should be none)NoSuchMethodException
- Thrown when the class somehow manages not to have a constructor
-
saveConfig
Saves a config object to the specified file in JSON format- Parameters:
config
- The object to be savedfile
- The file to which the object is saved- Throws:
IOException
- Thrown when the file has some issue saving
-