This is somehow working, but is it possible to sim...
# announcements
r
This is somehow working, but is it possible to simplify the function(for example no need for target parameter)?
Copy code
val doubleValue = optionalScalarValue(jsonObject, “value”, Double::class.java)

inline fun <reified T : Any> optionalScalarValue(jsonObject: JsonObject, field: String, target: Class<T>): T? {
        val element = jsonObject.get(field)

        when(target) {
            Double::class.java -> return element.asDouble as? T
        }
    
    	return null
    }