TheDocumentation 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.
TypeConverterAdapter interface is JungleConfig’s extension point for type serialization. Each adapter handles one Java type and teaches the framework two things: how to convert an object of that type into a plain string for storage, and how to reconstruct the object from that string when reading. Once registered, JungleConfig will use your adapter automatically whenever it encounters that type — identified by the simple class name returned from getType() — as the type tag stored alongside each entry.
The TypeConverterAdapter interface
The interface lives incom.codehack.JungleConfig.Core and has three methods:
getType()— must return exactly the value that will appear as the type tag in the backing file. The conventional choice isYourClass.class.getSimpleName(), which produces the unqualified class name (for example,"BigDecimal").ConvertToSave(Object)— receives the object to be stored and must return a non-null string representation. The string may be any format you choose, as long asCastToUsecan reconstruct the original value from it.CastToUse(String)— receives the stored string and must return a correctly-typed object. The returned value is cast to the requested type byNativeTypeConverter, so type mismatches will surface asClassCastExceptionat call sites.
Example: BigDecimal adapter
The ten built-in adapters (NativeBooleanAdapter, NativeIntagerAdapter, NativeStringAdapter, and so on) follow exactly this pattern. Here is a complete adapter for java.math.BigDecimal:
BigDecimal.toString() produces a canonical string (for example, "9.99" or "1.23E+5") that the BigDecimal(String) constructor can always reconstruct exactly, making it a safe round-trip format.
Registering the adapter
Custom adapters are passed to theNativeTypeConverter constructor’s varargs Adapters parameter. Because the JungleConfig convenience constructors (new JungleConfig(File), InMemoryConfig(), etc.) build the full stack internally with only the default adapters, you need to construct the stack yourself to inject a custom adapter. Wire all the layers in order from innermost to outermost:
FALLBACK_TO_SERIALIZE boolean.
Using the type hint overload
If the runtime class of your object does not produce the right simple name (for instance, because you’re passing a subclass or a value wrapped in another type), use the three-argumentSet overload to specify the adapter key explicitly:
getClass().getSimpleName() lookup.
The second constructor argument to
NativeTypeConverter is the FALLBACK_TO_SERIALIZE flag. When set to true (which is the default in all convenience constructors), any type that has no matching adapter is automatically serialized to JSON using Jackson and stored with the type tag "Json". When set to false, encountering an unmapped type throws InvalidConfigFormatException instead — useful in strict environments where unexpected types should be treated as programming errors rather than silently handled.