Annotation Interface 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(
@CustomLoader(loader = EnumListLoader.class)
List<MyEnum> modes
) {}
- 関連項目:
-
FieldLoader
-
必須要素の概要
必須要素
-
要素の詳細
-
loader
Class<? extends net.ririfa.yacla.loader.FieldLoader> loaderSpecifies the loader class responsible for transforming the raw value.- 戻り値:
- the class implementing
FieldLoader
-