Skip to content

Commit

Permalink
json: throw more descriptive errors from JsonNode.get() in case of mi…
Browse files Browse the repository at this point in the history
…ssing keys
  • Loading branch information
angryziber committed Feb 2, 2024
1 parent 43ed571 commit a31a861
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* oauth: JWT helper class introduced
* jdbc: introduced db.upsertBatch()
* jobs: runOnce() introduced for convenience
* json: throw more descriptive errors from JsonNode.get() in case of missing keys

# 1.6.4
* core: added common value types for Email, Phone, and Password, also StringValue base class
Expand Down
2 changes: 1 addition & 1 deletion json/src/JsonNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typealias JsonNode = Map<String, Any?>
typealias JsonList = List<JsonNode>

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

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

0 comments on commit a31a861

Please sign in to comment.