tech.pylons.lib.internal.jsonObjectExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libpylons Show documentation
Show all versions of libpylons Show documentation
Library providing common functionality for interacting with the Pylons ecosystem
The newest version!
package tech.pylons.lib.internal
import com.beust.klaxon.JsonObject
import java.lang.ClassCastException
fun JsonObject.fuzzyDouble(key : String) : Double {
return when (val v= this.getValue(key)) {
is String -> this.string(key)!!.toDouble()
is Number -> this.double(key)!!
else -> throw ClassCastException("$v is not convertible to Double")
}
}
fun JsonObject.fuzzyFloat(key : String) : Float {
return when (val v= this.getValue(key)) {
is String -> this.string(key)!!.toFloat()
is Number -> this.float(key)!!
else -> throw ClassCastException("$v is not convertible to Float")
}
}
fun JsonObject.fuzzyInt(key : String) : Int {
return when (val v= this.getValue(key)) {
is String -> this.string(key)!!.toInt()
is Number -> this.int(key)!!
else -> throw ClassCastException("$v is not convertible to Int")
}
}
fun JsonObject.fuzzyLong(key : String) : Long {
return when (val v= this.getValue(key)) {
is String -> this.string(key)!!.toLong()
is Number -> this.long(key)!!
else -> throw ClassCastException("$v is not convertible to Long")
}
}