Skip to content

Config Serializers

Ang edited this page Nov 18, 2022 · 1 revision

This is an unreleased feature that will be included in v3.0.0.

Why?

Config serializers are an extension to the config system that allows developers to parse the config options using any library they want. JSONSerializer is a Paragon class that parses config options into JSON format! It is the default serializer, but you can change it using the following instructions.

Using other serializers

Currently Paragon only has JSON, TOML, and YAML support in it using serializers. Don't want to use JSON? Here's how to change it. Head into your config class. (it should look something like below)

public class TestModConfig implements Config {
    public static final ConfigOption<String> DISCORD_USERNAME = new ConfigOption<>("username", new String("acee#1220"));
}

To change the config's serializer, simply add this override method. (in this example, I changed it to TOML)

@Override
public ConfigSerializer getSerializer() {
   return TOMLSerializer.builder(this).build();
}

Some serializers may also have settings. An example of this is the JSONSerializer allowing you to use custom GSON parsing. If you are interested in creating your own serializer, check out the existing serializer classes and use that to make your own!

Paragon is a simple, easy-to-use and lightweight config library.

Clone this wiki locally