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
) {}

See also

Functions

Link copied to clipboard
abstract fun annotationType(): Class<out Annotation>
Link copied to clipboard
abstract fun equals(p: Any): Boolean
Link copied to clipboard
abstract fun hashCode(): Int
Link copied to clipboard
abstract fun loader(): Class<out FieldLoader>
Specifies the loader class responsible for transforming the raw value.
Link copied to clipboard
abstract fun toString(): String