Kotlin data class: how to read the value of property if I don’t know its name at compile time?

Here is a function to read a property from an instance of a class given the property name (throws exception if property not found, but you can change that behaviour): import kotlin.reflect.KProperty1 import kotlin.reflect.full.memberProperties @Suppress(“UNCHECKED_CAST”) fun <R> readInstanceProperty(instance: Any, propertyName: String): R { val property = instance::class.members // don’t cast here to <Any, R>, it … Read more

Extend data class in Kotlin

The truth is: data classes do not play too well with inheritance. We are considering prohibiting or severely restricting inheritance of data classes. For example, it’s known that there’s no way to implement equals() correctly in a hierarchy on non-abstract classes. So, all I can offer: don’t use inheritance with data classes.

Jooq fetchInto with default value if field is null

The reason is that JSON_ARRAYAGG() (like most aggregate functions) produces NULL for empty sets, instead of a more “reasonable” empty []. Clearly, you never want this behaviour. So, you could use COALESCE, instead, see also this question: coalesce( jsonArrayAgg(jsonObject(book.ID, book.PRICE)), jsonArray() ) I’ll make sure to update all the other answers I’ve given on Stack … Read more