instantiateDataObject

fun <T : Any> instantiateDataObject(kClass: KClass<T>, metadata: DataObjectClassMetadata<T>, resolveValue: (ConstructorParamMetadata<T>) -> Any?): T

Instantiates a data class based on its metadata.

A missing value and a SQL NULL are two different things here, and resolveValue distinguishes them by returning MissingToken for the first and null for the second:

  • Absent — a declared default covers it. Without a default, a nullable property is set to null and a non-nullable one raises REQUIRED_ATTRIBUTE_MISSING.

  • Present and NULL — a value, so a default never replaces it. It reaches a nullable property as null and raises REQUIRED_ATTRIBUTE_MISSING for a non-nullable one, default or not.

Return

The instantiated object.

Parameters

kClass

The data class to instantiate; named in the exception message only.

metadata

Pre-computed constructor metadata, from ReflectionCache.getOrCreateDataObjectMetadata.

resolveValue

Supplies the value for one constructor parameter, or MissingToken when the source holds nothing under that name.

Throws

REQUIRED_ATTRIBUTE_MISSING if a non-nullable property has no value to take.