Daniel Pitts
10/23/2024, 8:24 PMinline fun <reified V> jsonConverter(
) = when {
JsonObjectBuilder::class.java.isAssignableFrom(V::class.java) -> JsonObjectBuilder.jsonConverter
JsonNode::class.java.isAssignableFrom(V::class.java) -> {
{ it: JsonNode<*> -> it }
}
else -> when (V::class) {
Int::class -> Int.jsonConverter
Double::class -> Double.jsonConverter
Float::class -> Float.jsonConverter
Long::class -> Long.jsonConverter
String::class -> String.jsonConverter
else -> throw IllegalArgumentException("Unsupported type: ${V::class}")
}
} as (V) -> JsonNode<*>
ephemient
10/23/2024, 8:40 PMreified
type parameters is a bad pattern. it needs to be resolved statically anyway, so you might as well have separate functions (possibly overloaded) and turn the IllegalArgumentException
case into a compile-time error (no such function) insteadDaniel Pitts
10/23/2024, 8:42 PM