fromProperties

inline fun <T : Any> fromProperties(properties: Properties, parent: T? = null): T

Parses a configuration namespace into a data class.

The data class must have at least one constructor which accepts only String or data class instances as its parameters.

This method will select a constructor to parse the configuration according to the following heuristic:

  • If the class only has one constructor matching the above constraint, that one will be picked.

  • If there are more than one constructor, the class will prefer to use the primary constructor.

  • Otherwise, an exception will be thrown.

Fields declared in the primary constructor can optionally be prefixed by an underscore (_) to facilitate data member hiding.

This method is also capable of parsing properties nested within namespaces, such as parent.child.prop=value using nested data classes.

If the class or constructor argument name does not match the property name, use Prefix to override the property name.

Parameters

T

Data class type.

properties

Properties instance to parse from.

parent

If not null, parent object to retrieve default values from.

Throws

if T does not satisfy the requirements of using this method.


fun <T : Any> fromProperties(clazz: KClass<out T>, properties: Properties, parent: T? = null): T

Parses a configuration namespace into a data class.

Parameters

clazz

Data class type.

properties

Properties instance to parse from.

parent

If not null, parent object to retrieve default values from.

Throws

if clazz does not satisfy the requirements of using this method. In particular:

  • clazz must be a data class.

  • parent must be an instance of clazz if not null.

  • There must exist only one constructor which accepts only data class instances or String in its parameters, or a primary constructor with the above constraint.


private fun <T : Any> fromProperties(clazz: KClass<out T>, properties: Properties, parent: T? = null, prefix: String): T

Parses a configuration namespace into a data class.

Parameters

clazz

Data class type.

properties

Properties instance to parse from.

parent

If not null, parent object to retrieve default values from.

prefix

Prefix of the configuration namespace.

Throws

if clazz does not satisfy the requirements of using this method. In particular:

  • clazz must be a data class.

  • parent must be an instance of clazz if not null.

  • There must exist only one constructor which accepts only data class instances or String in its parameters, or a primary constructor with the above constraint.