commit
58dc8a399e
2 changed files with 16 additions and 1 deletions
|
|
@ -1697,7 +1697,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
|
||||||
|
|
||||||
result = quote do:
|
result = quote do:
|
||||||
(
|
(
|
||||||
if `lenientJsonNode`.isNil: `workaround`[`optionGeneric`]() else: some[`optionGeneric`](`value`)
|
if `lenientJsonNode`.isNil or `jsonNode`.kind == JNull: `workaround`[`optionGeneric`]() else: some[`optionGeneric`](`value`)
|
||||||
)
|
)
|
||||||
of "table", "orderedtable":
|
of "table", "orderedtable":
|
||||||
let tableKeyType = typeSym[1]
|
let tableKeyType = typeSym[1]
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,21 @@ when isMainModule:
|
||||||
doAssert jDeser[0].n2.get() == "ABC"
|
doAssert jDeser[0].n2.get() == "ABC"
|
||||||
doAssert jDeser[1].n2.isNone()
|
doAssert jDeser[1].n2.isNone()
|
||||||
|
|
||||||
|
# Issue #6902
|
||||||
|
type
|
||||||
|
Obj = object
|
||||||
|
n1: int
|
||||||
|
n2: Option[int]
|
||||||
|
n3: Option[string]
|
||||||
|
n4: Option[bool]
|
||||||
|
|
||||||
|
var j0 = parseJson("""{"n1": 1, "n2": null, "n3": null, "n4": null}""")
|
||||||
|
let j0Deser = j0.to(Obj)
|
||||||
|
doAssert j0Deser.n1 == 1
|
||||||
|
doAssert j0Deser.n2.isNone()
|
||||||
|
doAssert j0Deser.n3.isNone()
|
||||||
|
doAssert j0Deser.n4.isNone()
|
||||||
|
|
||||||
# Table[T, Y] support.
|
# Table[T, Y] support.
|
||||||
block:
|
block:
|
||||||
type
|
type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue