This commit is contained in:
Dominik Picheta 2017-11-29 14:48:17 +00:00 • committed by Dominik Picheta
commit e0681715dc
2 changed files with 52 additions and 21 deletions

View file

@ -259,4 +259,20 @@ when isMainModule:
let data = %*{"name": "foo", "challenge": "bar"}
let msg = data.to(MsgChallenge)
doAssert msg.name == "foo"
doAssert msg.challenge == "bar"
doAssert msg.challenge == "bar"
block:
type
Color = enum Red, Brown
Thing = object
animal: tuple[fur: bool, legs: int]
color: Color
var j = parseJson("""
{"animal":{"fur":true,"legs":6},"color":"Red"}
""")
let parsed = to(j, Thing)
doAssert parsed.animal.fur
doAssert parsed.animal.legs == 6
doAssert parsed.color == Red