Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jun 6, 2020
1 parent 329e0fd commit 1867fa9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/pure/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,7 @@ proc fromJson*[T](a: var T, b: JsonNode) {.since: (1,3,5).} =
adding "json path" leading to `b` can be added in future work.
]#
checkJson b != nil, $($T, b)
when false: discard
elif compiles(fromJsonHook(a, b)): fromJsonHook(a, b)
when compiles(fromJsonHook(a, b)): fromJsonHook(a, b)
elif T is bool: a = to(b,T)
elif T is Table | OrderedTable:
a.clear
Expand Down Expand Up @@ -1344,9 +1343,9 @@ proc jsonTo*(b: JsonNode, T: typedesc): T {.since: (1,3,5).} =
fromJson(result, b)

proc toJson*[T](a: T): JsonNode {.since: (1,3,5).} =
## like `%` but allows custom serialization hook if `serialize(a: T)` is in scope
when false: discard
elif compiles(toJsonHook(a)): result = toJsonHook(a)
## serializes `a` to json; uses `toJsonHook(a: T)` if it's in scope to
## customize serialization, see strtabs.toJsonHook for an example.
when compiles(toJsonHook(a)): result = toJsonHook(a)
elif T is Table | OrderedTable:
result = newJObject()
for k, v in pairs(a): result[k] = toJson(v)
Expand Down
1 change: 0 additions & 1 deletion tests/stdlib/tjsonmacro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ static:

import strtabs

# xxx move to `tjson` pending https://github.com/nim-lang/Nim/pull/14572
proc testRoundtrip[T](t: T, expected: string) =
let j = t.toJson
doAssert $j == expected, $j
Expand Down

0 comments on commit 1867fa9

Please sign in to comment.