Prism Config - Lightweight Configuration Library for Java
Getting Started
Prism Config is a universal library for working with configuration files in Java projects. Although it can be installed as a Fabric mod due to the presence of a fabric.mod.json file, its main purpose is to be used as a dependency in other projects (JiJ). This is a standard Java library that is theoretically compatible with any version of Minecraft and any mod loader.
Integration for Developers
To add Prism Config to your project, you need to make the following changes to your build.gradle(.kts) file:
Groovy DSL:
repositories {
// ...
maven {
name = "Nova Committee - Release"
url = "https://maven.nova-committee.cn/releases/"
}
maven {
name = "Nova Committee - Snapshot"
url = "https://maven.nova-committee.cn/snapshots/"
}
}
dependencies {
// ...
implementation "io.github.prismwork:prismconfig:0.2.0:all"
// Or use the slim version if libraries are already included in your project (Gson, Jankson...)
// implementation "io.github.prismwork:prismconfig:0.2.0"
}
Kotlin DSL:
repositories {
// ...
maven {
name = "Nova Committee - Release"
url = uri("https://maven.nova-committee.cn/releases/")
}
maven {
name = "Nova Committee - Snapshot"
url = uri("https://maven.nova-committee.cn/snapshots/")
}
}
dependencies {
// ...
implementation("io.github.prismwork:prismconfig:0.2.0:all")
// Or use the slim version if libraries are already included in your project (Gson, Jankson...)
// implementation("io.github.prismwork:prismconfig:0.2.0")
}
Supported Formats
The library by default provides serializers and deserializers for the following formats:
- JSON (Gson)
- JSON5 (Jankson)
- TOML 0.4.0 (toml4j)
Usage Examples
Reading configuration from string:
String content;
MyConfig config = PrismConfig.getInstance().serialize(
MyConfig.class,
content,
DefaultSerializers.getInstance().json5(MyConfig.class) // Assuming config is in JSON5 format
);
Writing configuration to string:
MyConfig content;
String config = PrismConfig.getInstance().deserialize(
MyConfig.class,
content,
DefaultDeserializers.getInstance().json5(MyConfig.class) // Assuming config is in JSON5 format
);
Writing configuration to file:
MyConfig content;
File configFile;
PrismConfig.getInstance().deserializeAndWrite(
MyConfig.class,
content,
DefaultDeserializers.getInstance().json5(MyConfig.class), // Assuming config is in JSON5 format
configFile
);
Creating custom serializer:
String content;
PrismConfig.getInstance().serialize(
MyConfig.class,
content,
(string) -> {
// Implement your own parsing logic here
}
);
Used Libraries
- Jankson by falkreon - MIT license
- Gson by Google - Apache-2.0 license
- toml4j by Moandji Ezana - MIT license