public class ConfigBeanFactory extends java.lang.Object
Config.
See create(Config,Class).| Constructor and Description |
|---|
ConfigBeanFactory() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
create(Config config,
java.lang.Class<T> clazz)
Creates an instance of a class, initializing its fields from a
Config. |
public ConfigBeanFactory()
public static <T> T create(Config config, java.lang.Class<T> clazz)
Config.
Example usage:
Config configSource = ConfigFactory.load().getConfig("foo");
FooConfig config = ConfigBeanFactory.create(configSource, FooConfig.class);
The Java class should follow JavaBean conventions. Field types
can be any of the types you can normally get from a Config, including java.time.Duration or ConfigMemorySize. Fields may also be another JavaBean-style
class.
Fields are mapped to config by converting the config key to
camel case. So the key foo-bar becomes JavaBean
setter setFooBar.T - the type of the class to be instantiatedconfig - source of config informationclazz - class to be instantiatedConfigException.BadBean - If something is wrong with the JavaBeanConfigException.ValidationFailed - If the config doesn't conform to the bean's implied schemaConfigException - Can throw the same exceptions as the getters on Config