Skip to content

Commit

Permalink
Jsonutils: pass opt for object in object (nim-lang#16615)
Browse files Browse the repository at this point in the history
* jsonutils: fromJson forward opt param fix

* jsonutils: object in object test + fix: opt pass
  • Loading branch information
inv2004 authored and mildred committed Jan 11, 2021
1 parent f919f37 commit 0823103
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std/jsonutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ template fromJsonFields(newObj, oldObj, json, discKeys, opt) =
when key notin discKeys:
if json.hasKey key:
numMatched.inc
fromJson(val, json[key])
fromJson(val, json[key], opt)
elif opt.allowMissingKeys:
# if there are no discriminant keys the `oldObj` must always have the
# same keys as the new one. Otherwise we must check, because they could
Expand Down
6 changes: 6 additions & 0 deletions tests/stdlib/tjsonutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ template fn() =
a: int
b: string
c: float
type Bar = object
foo: Foo
boo: string
var f: seq[Foo]
try:
fromJson(f, parseJson """[{"b": "bbb"}]""")
Expand All @@ -131,6 +134,9 @@ template fn() =
doAssert true
fromJson(f, parseJson """[{"b": "bbb"}]""", Joptions(allowExtraKeys: true, allowMissingKeys: true))
doAssert f == @[Foo(a: 0, b: "bbb", c: 0.0)]
var b: Bar
fromJson(b, parseJson """{"foo": {"b": "bbb"}}""", Joptions(allowExtraKeys: true, allowMissingKeys: true))
doAssert b == Bar(foo: Foo(a: 0, b: "bbb", c: 0.0))

block testHashSet:
testRoundtrip(HashSet[string]()): "[]"
Expand Down

0 comments on commit 0823103

Please sign in to comment.