Custom Loader
annotation class CustomLoader
Specifies a custom FieldLoader to transform the raw parsed value into the final value assigned to the annotated field.
This is useful when the configuration format provides generic structures (e.g., lists, strings), and you need to convert them into specific types like enums, wrappers, or complex objects.
The loader is instantiated via its no-arg constructor and invoked during config loading.
Example:
public class EnumListLoader implements FieldLoader {
public Object load(Object raw) {
List<?> list = (List<?>) raw;
return list.stream()
.map(e -> MyEnum.valueOf(e.toString()))
.collect(Collectors.toList());
}
}
public record AppConfig(
= EnumListLoader.class)
List<MyEnum> modes
) {}
Content copied to clipboard