Skip to content

Commit a31a861

Browse files
committed
json: throw more descriptive errors from JsonNode.get() in case of missing keys
1 parent 43ed571 commit a31a861

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* oauth: JWT helper class introduced
55
* jdbc: introduced db.upsertBatch()
66
* jobs: runOnce() introduced for convenience
7+
* json: throw more descriptive errors from JsonNode.get() in case of missing keys
78

89
# 1.6.4
910
* core: added common value types for Email, Phone, and Password, also StringValue base class

json/src/JsonNode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ typealias JsonNode = Map<String, Any?>
77
typealias JsonList = List<JsonNode>
88

99
@kotlin.internal.HidesMembers
10-
inline fun <T> JsonNode.get(key: String) = get(key) as T
10+
inline fun <T> JsonNode.get(key: String) = (get(key) ?: throw NullPointerException("$key is absent")) as T
1111
inline fun <T> JsonNode.getOrNull(key: String) = get(key) as T?
1212

1313
inline fun JsonNode.getString(key: String) = get<String>(key)

0 commit comments

Comments
 (0)