Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seedstack/coffig
Lightweight configuration library written in Java.
https://github.com/seedstack/coffig
configuration java seedstack yaml
Last synced: 3 months ago
JSON representation
Lightweight configuration library written in Java.
- Host: GitHub
- URL: https://github.com/seedstack/coffig
- Owner: seedstack
- License: mpl-2.0
- Created: 2016-02-19T12:31:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-23T11:35:40.000Z (over 3 years ago)
- Last Synced: 2023-10-27T09:20:47.466Z (over 1 year ago)
- Topics: configuration, java, seedstack, yaml
- Language: Java
- Homepage:
- Size: 539 KB
- Stars: 3
- Watchers: 10
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SeedStack config library "Coffig"
[![Build status](https://travis-ci.org/seedstack/coffig.svg?branch=master)](https://travis-ci.org/seedstack/coffig) [![Coverage Status](https://coveralls.io/repos/seedstack/coffig/badge.svg?branch=master)](https://coveralls.io/r/seedstack/coffig?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.seedstack.coffig/coffig/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/org.seedstack.coffig/coffig)
Coffig is a simple and powerful configuration library for the Java language. It is built upon the idea of mapping configuration trees to Java objects. The following configuration tree in YAML:
```yaml
some:
string: value1
array: [1, 2, 3]
object:
attr1: value1
attr2: [iris, jasmine, kiwi]
```
Can be retrieved as simply as:```java
Coffig coffig = Coffig.builder().withProviders(new JacksonProvider().addSource("url/to/file.yaml")).build();
String stringValue = coffig.get(String.class, "some.string");
int[] intArray = coffig.get(int[].class, "some.array");
MyPojo myPojo = coffig.get(MyPojo.class, "some.object");
String defaultValue = coffig.getOptional(String.class, "unknown.node").orElse("default");
```## Mapping
Coffig is able to map any Java class by introspecting its members but can handle special cases with dedicated mappers. Mappers for several types are built-in:* Array,
* List,
* Set,
* Map,
* Enum,
* Optional,
* URI/URL,
* Properties,
* Class.You can add you own mappers by implementing the `ConfigurationMapper` interface and registering it through the [ServiceLoader](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) mechanism.
## Providers
Multiple providers can be used at once, each providing a separate configuration tree that will be merged into a global one. Several providers are built-in:
* Jackson (for YAML and JSON sources),
* Environment variables,
* System properties.You can add you own mappers by implementing the `ConfigurationProvider` interface and registering it through the [ServiceLoader](http://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) mechanism.
# Copyright and license
This source code is copyrighted by [The SeedStack Authors](https://github.com/seedstack/seedstack/blob/master/AUTHORS) and
released under the terms of the [Mozilla Public License 2.0](https://www.mozilla.org/MPL/2.0/).