Package com.typesafe.config
Class ConfigBeanFactory
- java.lang.Object
-
- com.typesafe.config.ConfigBeanFactory
-
public class ConfigBeanFactory extends java.lang.Object
Factory for automatically creating a Java class from aConfig. Seecreate(Config,Class).- Since:
- 1.3.0
-
-
Constructor Summary
Constructors Constructor Description ConfigBeanFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tcreate(Config config, java.lang.Class<T> clazz)Creates an instance of a class, initializing its fields from aConfig.
-
-
-
Constructor Detail
-
ConfigBeanFactory
public ConfigBeanFactory()
-
-
Method Detail
-
create
public static <T> T create(Config config, java.lang.Class<T> clazz)
Creates an instance of a class, initializing its fields from aConfig. 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 aConfig, includingjava.time.DurationorConfigMemorySize. Fields may also be another JavaBean-style class. Fields are mapped to config by converting the config key to camel case. So the keyfoo-barbecomes JavaBean settersetFooBar.- Type Parameters:
T- the type of the class to be instantiated- Parameters:
config- source of config informationclazz- class to be instantiated- Returns:
- an instance of the class populated with data from the config
- Throws:
ConfigException.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 onConfig- Since:
- 1.3.0
-
-