Fork me on GitHub


There are some debugging facilities that are available in Properties files that we wanted to keep in the OWNER API.

The toString() method

The toString() method is helpful to see the content of a Config object using a log statement:

interface MyConfig extends Config {
    int maxThreads();

    int maxFolders();

    String defaultName();

public static void main(String[] args) {
    MyConfig cfg = ConfigFactory.create(MyConfig.class);
    System.out.println("cfg = " + cfg);
    // output will be: 
    // "cfg = {, max.folders=99, max.threads=25}"

The list() methods

In your mapping interfaces you can optionally define one of the following methods that may be convenient for debugging:

void list(PrintStream out);
void list(PrintWriter out);

Those two methods were available in Java Properties to help the debugging process.
You can implement Accessible that defines the above methods, or just add them manually.

You can use them to print the resolved properties (and eventual overrides that may occur when using the LoadType.MERGE):

public interface SampleConfig extends Config {
    int httpPort();

    void list(PrintStream out); // manually defined

ServerConfig cfg = ConfigFactory.create(ServerConfig.class);

You can also do the same implementing the Accessible interface, that declares the list() methods for you:

public interface SampleConfig extends Accessible {
    int httpPort();

ServerConfig cfg = ConfigFactory.create(ServerConfig.class);
cfg.list(System.out); // list() is defined in Accessible interface