Created
February 10, 2019 12:54
-
-
Save bastman/df8a7dda8dd30bbc9256845ecbd521ab to your computer and use it in GitHub Desktop.
kotlin: isNullable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T> query(content: String, query: String): T { | |
try { | |
val expression: Expression<JsonNode> = compile(query = query) | |
val resultNode: JsonNode = search(content = content, expression = expression) | |
val converted: T = converter.convertValue(resultNode) | |
val isNullable: Boolean = null is T | |
if (converted == null && !isNullable) { | |
error("Failed to convert to (non-nullable) instance of ${T::class} from $resultNode .") | |
} | |
return converted | |
} catch (all: Throwable) { | |
error("JQ Failed! query: $query - reason: ${all.message} ") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment