resolve

fun <T : Any> resolve(instance: T, klass: KClass<T>): T

Creates a new instance of T where any field annotated with @Env is replaced by the corresponding environment variable value, if set.

The method walks the primary constructor parameters of klass, reads the current property value from instance, checks for an @Env annotation, and queries System.getenv. For nested data class parameters the method recurses.

If no environment variable overrides any field, the original instance is returned (identity equality, no copy).

Return

A new instance with overridden fields, or the same instance if nothing changed.

Parameters

T

The data class type.

instance

The already-deserialized data class instance.

klass

The KClass token for T, used for reflection.

Throws

If an environment variable value cannot be converted to the target numeric type (e.g. "abc" for an Int field).