3

Our application is using a reference.conf to provide defaults for one of our POJO's that carries configuration information. Say the Pojo is:

class Person {
  String first;
  String last;
    // corresponding setters / getters not shown
}

The reference.conf has the defaults:

Person {
 first:  "joe"
 last:  "shmoe"
}

So if your application.conf had:

Person {
 first:  "mike"
}

Thus when you did this:

  public static Person getInstance(Config config) {
    return ConfigBeanFactory.create(config.getConfig("Person"), Person.class);
  }

You'd get back a Person with first/last == mike/shmoe

Now..say I have some users who are not getting enough sleep, and one of them misconfigures their application like this (mis-spelling 'first'):

Person {
 frist:  "mike"
}

The way I'm doing things now the Pojo loaded from this config has default first/last == joe/shmoe. There is no warning about the mis-spelling ("frist").

I could write code to reflect against my Bean class and see what attributes the user provided which don't correspond to the available setters, and then raise an error if any 'wrong' attributes are found.
But it seems like someone (maybe even the Typesafe config base library) must already have this feature.

Any pointer to a good existing way to do this very much appreciated.

Chris Bedford
  • 2,560
  • 3
  • 28
  • 60

0 Answers0