Jean
![]()
Jean is a first-class configuration Java library built to provide a simple and effective way to manage application configuration. Jean offers you fast and easy-to-use APIs with rich serializer support, allowing you to read and write configuration files in various formats such as JSON, YAML, TOML, and more.
Source Code — Documentation — Maven Central
Quick example
Create a configuration class:
Instantiate Jean and load & save configuration from/to a JSON file:
Installation
Jean is available on Maven Central.
Name | Description | Version |
|---|---|---|
Jean Core | Core functionality | |
Jean GSON | GSON serializer for JSON files | |
Jean SnakeYAML | SnakeYAML serializer for YAML files | |
Jean JToml | JToml serializer for TOML files |
Creating a Jean instance
There are two ways to create a Jean instance.
new Jean(Path, Serializer, LoadOptions)Constructs a new Jean instance with the specified configuration directory, serializer and default load options.
new Jean(Path, Serializer)Constructs a new Jean instance with the specified configuration directory and serializer. Uses
LoadOptions#DEFAULTfor load options.
The Path parameter specifies the directory where configuration files will be stored. The Serializer parameter defines the serialization format to be used for reading and writing configuration files. The default load options are used when loading configurations w/o specifying custom options.
Serializers
Jean supports multiple serializers for different file formats. The following serializers are available:
GsonSerializerSerializer implementation using Gson
SnakeYamlSerializerSerializer implementation using SnakeYAML
JTomlSerializerSerializer implementation using JToml
PropertiesSerializerSerializer implementation using Java Properties format
Each serializer may require (optional) additional parameters for customization. Each serializer has a default constructor, creating the typical use case, and other constructor that allows you to specify the underlying serializer (e.g., Gson instance).
Usage
Once you have created a Jean instance, you can use it to load and save configuration objects.
Loading configurations
T getOrLoad(Class<T> configClass)Loads the configuration of the specified class from the corresponding file. If the file does not exist, a new instance of the configuration class is created with default values and saved to the file. The configuration file will be named after the full class name with dots replaced by underscores and the appropriate file extension based on the serializer.
T getOrLoad(String name, Class<T> configClass)Loads the configuration of the specified class from the specified file name. If the file does not exist, a new instance of the configuration class is created with default values and saved to the file. If appropriate file extension is not provided, it will be appended based on the serializer.
T getOrLoad(Class<T> configClass, LoadOptions)Loads the configuration of the specified class from the corresponding file with custom load options. The configuration file will be named after the full class name with dots replaced by underscores and the appropriate file extension based on the serializer.
T getOrLoad(String name, Class<T> configClass, LoadOptions)Loads the configuration of the specified class from the specified file name with custom load options. If appropriate file extension is not provided, it will be appended based on the serializer.
Saving configurations
void save(Object config)Saves the specified configuration object to the corresponding file. The configuration file will be named after the full class name with dots replaced by underscores and the appropriate file extension based on the serializer.
void save(String name, Object config)Saves the specified configuration object to the specified file name. If appropriate file extension is not provided, it will be appended based on the serializer.
Miscellaneous
void clearCache()Clears the internal cache of loaded configurations. This forces Jean to reload configurations from files the next time they are requested.
LoadOptions
You may configure how Jean loads configurations using the LoadOptions class.
saveOnLoadWhether to save the configuration back to the file after loading. Default is
false.
Internal caching
Jean maintains an internal thread-safe cache of loaded configurations to optimize performance and reduce file I/O operations. When a configuration is requested via #getOrLoad(), Jean first checks the cache. If the configuration is found in the cache, it is returned directly without reading from the file. If not found, Jean loads the configuration from the file, stores it in the cache, and then returns it.
Custom serializers
You may implement your own custom serializers by implementing the Serializer interface.