Simple and fast property-based configuration library for JVM apps, similar to JSON5 standard, also with JSON & YAML-like targets 🧾
APACHE-2.0 License
Simple and fast configuration library for JVM based apps, powered by CDN (Configuration Data Notation) format, based on enhanced JSON for Humans standard. Handles CDN, JSON and YAML-like configurations with built-in support for comments and automatic scheme updates.
repositories {
maven { url 'https://repo.panda-lang.org/releases' }
}
dependencies {
// Default
implementation 'net.dzikoysk:cdn:1.14.5'
// Kotlin wrapper
implementation 'net.dzikoysk:cdn-kt:1.14.5'
}
You can find all available versions in the repository:
A brief summary of how to use the library.
public final class AwesomeConfig {
@Description("# Comment")
public String property = "default value";
}
Handling:
Cdn cdn = CdnFactory.createStandard();
File configurationFile = new File("./config.cdn");
// Load configuration
AwesomeConfig configuration = cdn.load(Source.of(configurationFile), AwesomeConfig.class).orThrow(identity());
// Modify configuration
configuration.property = "modified value";
// Save configuration
cdn.render(configuration).orThrow(identity());
To explore all features, take a look at other chapters.
By default, CDN is meant to use class-based configuration. It means that configurations are accessed through the standard Java instance. Let's say we'd like to maintain this configuration:
hostname: 'localhost'
At first, every configuration is loaded into the Configuration
object.
Configuration configuration = cdn.load("hostname: localhost")
String hostname = configuration.getString("hostname", "default value, if the requested one was not found")
To avoid such a cringe configuration handling, we can just map this configuration into the Java object. Let's declare the scheme:
public final class Config {
public String hostname = "default value";
}
The last thing to do is to provide this class during the load process:
Config config = cdn.load("hostname: localhost", Config.class)
config.hostname // returns 'localhost'
Configurations can be updated in both variants. As you can see in the previous chapter, we've declared hostname field as non-final. It means we can just update it's value and CDN will update this field during next render.
config.hostname = "new value";
For configuration without scheme, we can use setString
method:
configuration.setString("hostname", "new value");
CDN can render configuration elements and entities using render
methods.
The output depends on the installed format.
Various formats ae supported through the Feature
api.
Available format features:
Output comparison: