owner icon indicating copy to clipboard operation
owner copied to clipboard

Is it possible to define non-public Preprocessors?

Open drapostolos opened this issue 8 years ago • 0 comments

I want to add a Preprocessor to one of my properties, as in below code. I would also like the ToUpperCase Preprocessor NOT to be exposed in my public API (i.e. make it private or package-private), is it possible? The below code fails due to ToUpperCase is private. Are there any workarounds?

If no workaround is available, would it make sense to change OWNER to suppress Java language access checking when instantiating classes through reflection? I mean, it would be nicer if OWNER didn't force API developers to expose more than necessary in their API's.

If above makes sense I can provide a pull request.

import org.aeonbits.owner.Config;
import org.aeonbits.owner.ConfigFactory;
import org.aeonbits.owner.Preprocessor;

public class Example {

    public static void main(String[] args) {

        MyConfig conf = ConfigFactory.create(MyConfig.class);
        System.out.println(conf.propA());

    }

    public interface MyConfig extends Config {

        @Key("prop.a")
        @DefaultValue("a")
        @PreprocessorClasses(ToUpperCase.class)
        String propA();
    }

    private static class ToUpperCase implements Preprocessor {

        @Override
        public String process(String input) {
            return input.toUpperCase();
        }
    }
}

drapostolos avatar Oct 04 '16 14:10 drapostolos