Hacker News new | ask | show | jobs
by elric 141 days ago
I use PKL for most of my configuration needs these days. But PKL is only a format, it doesn't say where to store the config. Could I use Externalized Properties to e.g. fetch config from some random source but have it be PKL?
1 comments

Definitely! There's no limit on what configuration formats Externalized Properties can support as you can implement custom `Resolver`s to retrieve from any source and format e.g.

    public class PklResolver implements Resolver {
        public Optional<String> resolve(InvocationContext context, String propertyName) {
            return getFromPklConfig(propertyName);
        }
    }


    // Register custom resolver when building ExternalizedProperties

    ExternalizedProperties externalizedProperties = ExternalizedProperties.builder()
        .resolvers(new PklResolver(...))
        .build();

    AppProperties appProperties = externalizedProperties.initialize(AppProperties.class);

    // Resolves config from PklResolver

    String myConfig = appProperties.myConfig();