Skip to content

Repository files navigation

Jackson for Commons Configuration 2

Build JavaDoc GitHub Maven Central License

This project adds support for FasterXML's Jackson to Apache Commons Configuration 2.

Installation

Add the library as a dependency to your project. In Gradle, add to your dependencies block

implementation 'com.virtlink.commons:commons-configuration2-jackson:1.3.5'

Or in Gradle Kotlin DSL, add to your dependencies block

implementation("com.virtlink.commons:commons-configuration2-jackson:1.3.5")

In Maven, add to your <dependencies> tag

<dependency>
    <groupId>com.virtlink.commons</groupId>
    <artifactId>commons-configuration2-jackson</artifactId>
    <version>1.3.5</version>
</dependency>

Otherwise download the latest release and add the .jar to your project's classpath.

Usage

Import the project's namespace.

import com.virtlink.commons.configuration2.jackson.JsonConfiguration;

Instantiate the configuration class directly

JsonConfiguration config = new JsonConfiguration();

or create a new configuration through the configuration builder,

import org.apache.commons.beanutils.PropertyUtils;

Parameters params = new Parameters();
FileBasedConfigurationBuilder<JsonConfiguration> builder
    = new FileBasedConfigurationBuilder<>(JsonConfiguration.class);
JsonConfiguration config = builder.configure(params
     .fileBased()
     .setFileName("example.json")).getConfiguration();

Note: You need to add commons-beanutils as a dependency and import org.apache.commons.beanutils.PropertyUtils to make builders work, otherwise you get a ClassNotFoundException: org.apache.commons.beanutils.PropertyUtils when creating the builder parameters.

You can use the configuration to read from a Reader

try (Reader reader = new BufferedReader(new FileReader("settings.json"))) {
	config.read(reader);
}

or write to a Writer

try (Writer writer = new PrintWriter("settings.json", "UTF-8")) {
	config.write(writer);
}

Also refer to the API documentation.

Questions and Issues

If you have a question, ask it on Stack Overflow under the apache-commons-config tag.

If you have an issue or found a bug, please search the list of reported issues for a solution or workaround, or create a new issue.

Copyright and License

Copyright © 2015-2023 - Daniel A. A. Pelsmaeker

The code and files in this project are licensed under the Apache License, Version 2.0. You may use the files in this project in compliance with the license.

About

Add support for FasterXML's Jackson to Apache Commons Configuration 2.

Resources

Code of conduct

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages