parent
b0e26d8fbf
commit
7d640e0943
2 changed files with 19 additions and 0 deletions
|
|
@ -1052,6 +1052,8 @@ when defined(nimFixedForwardGeneric):
|
||||||
dst = jsonNode.bval
|
dst = jsonNode.bval
|
||||||
|
|
||||||
proc initFromJson(dst: var JsonNode; jsonNode: JsonNode; jsonPath: var string) =
|
proc initFromJson(dst: var JsonNode; jsonNode: JsonNode; jsonPath: var string) =
|
||||||
|
if jsonNode == nil:
|
||||||
|
raise newException(KeyError, "key not found: " & jsonPath)
|
||||||
dst = jsonNode.copy
|
dst = jsonNode.copy
|
||||||
|
|
||||||
proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) =
|
proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) =
|
||||||
|
|
|
||||||
17
tests/stdlib/t15835.nim
Normal file
17
tests/stdlib/t15835.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = object
|
||||||
|
ii*: int
|
||||||
|
data*: JsonNode
|
||||||
|
|
||||||
|
block:
|
||||||
|
const jt = """{"ii": 123, "data": ["some", "data"]}"""
|
||||||
|
let js = parseJson(jt)
|
||||||
|
discard js.to(Foo)
|
||||||
|
|
||||||
|
block:
|
||||||
|
const jt = """{"ii": 123}"""
|
||||||
|
let js = parseJson(jt)
|
||||||
|
doAssertRaises(KeyError):
|
||||||
|
echo js.to(Foo)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue