validateValue
Validates whether a runtime value matches the expected Kotlin type.
This is an internal framework function used during object mapping to ensure type safety. For collections (List, Map), validates the type of the first non-null element.
Return
The original value if validation passes.
Parameters
value
The value to validate (can be null).
targetType
The expected Kotlin type (KType) including generic parameters.
Throws
if the value's type doesn't match the target type.