ConfigBeanFactory

Factory for automatically creating a Java class from a [[Config]]. See [[ConfigBeanFactory#create]].

Factory for automatically creating a Java class from a [[Config]]. See [[ConfigBeanFactory#create]].

Since

1.3.0

class Object
trait Matchable
class Any

Value members

Concrete methods

def create[T](config: Config, clazz: Class[T]): T

Creates an instance of a class, initializing its fields from a [[Config]].

Creates an instance of a class, initializing its fields from a [[Config]].

Example usage:

val configSource: Config = ConfigFactory.load().getConfig("foo");
val config: FooConfig = ConfigBeanFactory.create(configSource, classOf[FooConfig]);

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.

Value Params
<T>

the type of the class to be instantiated

clazz

class to be instantiated

config

source of config information

Returns

an instance of the class populated with data from the config

Throws
ConfigException

Can throw the same exceptions as the getters on [[Config]]

ConfigException#BadBean

If something is wrong with the JavaBean

ConfigException#ValidationFailed

If the config doesn't conform to the bean's implied schema

Since

1.3.0