Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/igoodie/runtimegoodies

♾️ Utility entities to enhance runtime stuff. (Including the ConfiGoodies!)
https://github.com/igoodie/runtimegoodies

configuration java java-library json orm runtime toml universal

Last synced: about 1 month ago
JSON representation

♾️ Utility entities to enhance runtime stuff. (Including the ConfiGoodies!)

Awesome Lists containing this project

README

        



RuntimeGoodies Logo


A Java library for representing, reading, validating and fixing externally stored files/configs.



































# Description

RuntimeGoodies is a Java 8+ library that aims to solve a fundamental problem: reading & maintaining program
configurations. It attemps to load external config files into
declared
POJO
s with its custom annotations and validators. It even fixes the config when necessary *(e.g an empty field is
replaced by the default value and saved)*

It comes with a few modules to support following formats:

- JSON (module: `com.github.iGoodie.RuntimeGoodies:json:`)
- TOML 0.4.0 (module: `com.github.iGoodie.RuntimeGoodies:toml:`)

Out of the box, it comes with a built-in way to universally represent entities during runtime called Goodies. Goodies
are serializable in any format desired. They have a very similar structure
to JSON elements. Goodies do not exist outside the runtime, they are
in-memory only.

# How to Use?

This library uses JitPack to serve artifacts that can be
depended on. If your project is a **Gradle** project, use following steps:

1. Add JitPack repository to your `build.gradle` file:

```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

2. Depend on desired release. (Replace `` with the version of choice)

```groovy
dependencies {
implementation 'com.github.iGoodie.RuntimeGoodies:core:'
implementation 'com.github.iGoodie.RuntimeGoodies:json:' // Format of choice, see supported formats above
}
```

List of all available the versions can be found under GitHub
Releases

section. Alternatively, `master-SNAPSHOT` can be used to depend on the nightly version (at your own risk).

# Getting Started

1. Create a POJO (ConfiGoodie) to represent the external config file. (In this example, external file is in JSON format)

```java
public class ServerConfig extends JsonConfiGoodie {

@Goodie // <-- Annotate the fields you want to be exposed with @Goodie
String username, password;

@Goodie
Date launchDate; // Some values are converted from string!

@Goodie
int port = 3000; // You can declare default values!

@Goodie
DBConnection mongodbConnection; // Other ConfiGoodies/POJOs can be nested too!

@Goodie
DBConnection mysqlConnection = defaultValue(() -> {
DBConnection connection = new DBConnection();
connection.ports = Arrays.asList(3000, 3001, 3002);
return connection;
}); // You can declare default values via your own supplier!

public static class DBConnection {

@Goodie
String uri = "localhost:3000";

@Goodie
List ports; // You can have Lists as well!

@Goodie
Map aliases; // Guess what, Maps too!

}

}
```

2. Instance that POJO and let RuntimeGoodie read (and fix if necessary) for you!

```java
public class Test {

public static void main(String[] args) {
File configFile = new File("path/to/config.json");

// Tadaaa! Your config object is now read, validated and fixed accordingly.
ServerConfig config = new ServerConfig().readConfig(configFile);

// Note that, the call above will override the file if changes are made during fixing phase.
// Check out the Wiki, if you want to customize that behavior.
}

}
```

In order to learn more about what else you can do, check the
Wiki
out!

## Facing an Issue?

- Join our Discord Server - https://discordapp.com/invite/KNxxdvN
- Create an issue on Github: https://github.com/iGoodie/RuntimeGoodies/issues
- Contact iGoodie via Discord: iGoodie#1945

## License

© 2021 Taha Anılcan Metinyurt (iGoodie)

For any part of this work for which the license is applicable, this work is licensed under
the [Attribution-NonCommercial-NoDerivatives 4.0 International](http://creativecommons.org/licenses/by-nc-nd/4.0/)
license. (See LICENSE).

Creative Commons License