EasyConfig is a Java library designed to simplify configuration file handling using JSON files.
- Simple Configuration Handling: EasyConfig provides straightforward methods to manage JSON-based configuration files.
- Flexible Usage: Easily set, get, and modify configuration options within your Java application.
- Customizable Structure: Allows nesting configurations within parent keys for organized data storage.
You will find all the dependencies in the pom.xml
file.
Dependency | Version | Source |
---|---|---|
com.google.code.gson | 2.10.1 | mvn |
To use EasyConfig in your Java project, follow these steps:
- Download: Clone or download the EasyConfig repository from GitHub.
- Include Library: Add the EasyConfig library to your Java project's build path.
-
Initialize EasyConfig:
// Example initialization Config config = new Config("path/to/config/folder", "config.json");
-
Set Configuration Values:
// Set a value directly config.put("key", "value"); // Set a value under a parent key config.putInParent("parentKey", "key", "value");
-
Retrieve Configuration Values:
// Get a value by key Object value = config.get("key"); // Get a value from under a parent key Object parentValue = config.getFromParent("parentKey", "key");
-
Modify and Save Configuration
// Get a value by key Object value = config.get("key"); // Get a value from under a parent key Object parentValue = config.getFromParent("parentKey", "key");
{
"version": "1.0.0",
"client": {
"author": "NilsJanosch",
"admin": true,
"age": 15
}
}
This JSON structure demonstrates the usage of put() and putInParent() methods in EasyConfig:
put()
: Used to directly set a key-value pair in the configuration. Here, the "version" key is set to "1.0.0".
putInParent()
: This method is utilized to nest values under a parent key. In this case, within the "client" object, three attributes are added:
"author"
: Holds the value "NilsJanosch"
.
"admin"
: Represents a boolean value, true
.
"age"
: Stores an integer value, 15
.
These methods allow easy manipulation and organization of configuration data within the JSON file using the EasyConfig library.
Contributions are welcome! Feel free to raise issues or submit pull requests to help improve EasyConfig.
This project is licensed under the MIT License - see the LICENSE file for details.