Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/himansaBro/JungleConfig/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through the minimum steps needed to add JungleConfig to an existing Maven project, write a handful of typed configuration values to a file, and read them back — all without any XML configuration or framework setup. By the end you will have a working config file on disk and a clear picture of the core API.
1

Add the Maven dependency

Add JungleConfig and its three Jackson dependencies to your pom.xml. Jackson handles POJO serialisation and Java Time support; all three modules are required.
<dependencies>
  <!-- JungleConfig -->
  <dependency>
    <groupId>com.codehack</groupId>
    <artifactId>Jconfig</artifactId>
    <version>1.0-SNAPSHOT</version>
  </dependency>

  <!-- Jackson core (required for POJO and collection support) -->
  <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.18.3</version>
  </dependency>
  <dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
    <version>2.18.2</version>
  </dependency>
  <dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.17.1</version>
  </dependency>
</dependencies>
After saving, run mvn dependency:resolve to confirm Maven can download the artifacts.
2

Create a JungleConfig instance

Point a JungleConfig object at a file on disk. If the file does not exist, JungleConfig creates it automatically.
import com.codehack.JungleConfig.JungleConfig;
import java.io.File;

public class AppConfig {
    public static void main(String[] args) {
        // File-backed config — created automatically if absent
        JungleConfig config = new JungleConfig(new File("app.conf"));

        System.out.println("Config ready. Keys: " + config.getAllKeys());
    }
}
Use JungleConfig.InMemoryConfig() during unit tests so no file is created on disk and the config is discarded when the JVM exits.
3

Store primitive values

Use Set(key, value) to persist any of the built-in types. The method is fluent, so you can chain multiple calls. Each stored value is automatically tagged with its Java type name in the config file.
config
    .Set("app.name",    "MyService")       // String
    .Set("app.port",    8080)              // Integer
    .Set("app.debug",   true)              // Boolean
    .Set("app.timeout", 30_000L)           // Long
    .Set("app.ratio",   0.95)             // Double
    .Set("app.version", 2.1f);            // Float
The resulting app.conf file will contain lines like:
JConfig001
app.name:String=MyService
app.port:Integer=8080
app.debug:Boolean=true
app.timeout:Long=30000
app.ratio:Double=0.95
app.version:Float=2.1
4

Read values back

JungleConfig offers two read styles. Use the lowercase get(key, Class) when you are certain the key exists — it returns the value directly or null. Use the uppercase Get(key, Class) when the key may be absent — it returns an Optional<T>, forcing you to handle the missing case explicitly.
// Direct read — returns null if the key does not exist
String  name    = config.get("app.name",    String.class);
int     port    = config.get("app.port",    Integer.class);
boolean debug   = config.get("app.debug",   Boolean.class);
long    timeout = config.get("app.timeout", Long.class);
double  ratio   = config.get("app.ratio",   Double.class);

System.out.printf("Starting %s on port %d (debug=%b)%n", name, port, debug);

// Safe Optional read — use when the key might not exist yet
config.Get("app.maxRetries", Integer.class)
      .ifPresentOrElse(
          r  -> System.out.println("Max retries: " + r),
          () -> System.out.println("app.maxRetries not set, using default 3")
      );
5

Store and read a POJO

For structured data, use SetPOJO(key, object) to serialise any Java bean to the config file, then read it back with get(key, YourClass.class). The POJO must have a no-argument constructor and public fields or standard getters/setters (standard Jackson rules apply).
// Define a simple POJO
public static class DatabaseSettings {
    public String host;
    public int    port;
    public String name;

    public DatabaseSettings() {}

    public DatabaseSettings(String host, int port, String name) {
        this.host = host;
        this.port = port;
        this.name = name;
    }
}

// Store it
DatabaseSettings db = new DatabaseSettings("localhost", 5432, "mydb");
config.SetPOJO("db.settings", db);

// Read it back
DatabaseSettings restored = config.get("db.settings", DatabaseSettings.class);
System.out.println("DB host: " + restored.host); // localhost
System.out.println("DB port: " + restored.port); // 5432
6

Store and read a collection

Generic collections need a Jackson TypeReference so the element type is preserved at runtime. Use Set(key, list) to write and getCollection(key, typeRef) (or GetCollection for the Optional variant) to read.
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.Arrays;
import java.util.List;

// Store a list of strings
List<String> featureFlags = Arrays.asList("dark-mode", "beta-search", "new-dashboard");
config.Set("app.features", featureFlags);

// Read it back with a TypeReference
List<String> flags = config.getCollection(
    "app.features",
    new TypeReference<List<String>>() {}
);
flags.forEach(f -> System.out.println("Feature enabled: " + f));

// Optional variant — safe when the key might not exist
config.GetCollection("app.features", new TypeReference<List<String>>() {})
      .ifPresent(list -> System.out.println("Total features: " + list.size()));
Always use getCollection / GetCollection with a TypeReference for any generic type (List<T>, Map<K,V>, etc.). Using get with List.class discards the element type and will return a list of raw LinkedHashMap objects instead.

Next steps

Configuration modes

Compare File, EncryptedFile, InMemory, and FlatJson modes and learn when to choose each one.

Transactions

Use BeginTransaction, Commit, and Rollback to make config updates atomic.

Encryption

Protect sensitive values at rest with the built-in AES-encrypted file mode.

API reference

Full reference for every method on the JungleConfig class.

Build docs developers (and LLMs) love