I have a union type ContentNode can be either a P, Br, or Text. The P can have 
children of type ContentNode:
    
    
    type
      ContentNodeKind* = enum
        P,
        Br,
        Text
      ContentNode* = object
        case kind*: ContentNodeKind
        of P: pChildren*: seq[ContentNode]
        of Br: nil
        of Text: textStr*: string
    
    
    Run

Now I can serialize it using the json module just fine, but when I try to 
deserialize it with the to() proc it just ignores the children of my P node:
    
    
    let mynode = ContentNode(kind: P, pChildren: @[
      ContentNode(kind: Text, textStr: "mychild"),
      ContentNode(kind: Br)
    ])
    
    echo "Original: " & $mynode
    
    let serialized = $(%*mynode)
    echo "Serialized: " & serialized
    
    let deserialized = parseJson(serialized).to(ContentNode)
    echo "Deserialized: " & $deserialized
    
    #Original: (kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: 
Br)])
    #Serialized: 
{"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}
    #Deserialized: (kind: P, pChildren: @[])
    
    
    Run

So what am I doing wrong? Am I not supposed to use to() for arbitrarily nested 
structures?

Reply via email to