Json2CSharp / Json2CSharpCodeGenerator

Microsoft Reciprocal License
292 stars 81 forks source link

Wrong result for recursive elements #78

Closed filipopo closed 2 years ago

filipopo commented 2 years ago

I'm writing a sort of tree/xml like structure where each element can contain one or more elements with the same types of key/value pairs and I noticed that the convertor makes a "Element3" class, probably incrementing by each layer e.g:

{
    "number": 1,
    "elements": [{
        "name": "node1",
        "attrs": {
            "id": "1"
        },
        "elements": [{
                "name": "node2",
                "attrs": {
                    "id": "2"
                },
                "elements": [{
                    "name": "node3",
                    "attrs": {
                        "id": "3"
                    }
                }]
            }
        ]
    }]
}

The root and element classes reference just "Element" though, which would be correct if the "Element3" class was just "Element": image The result is even more out of sync if the Root class is made to essentially contains itself, the same as "Element3" but both classes would be made

marblekirby commented 2 years ago

I am experiencing the same issue, with a Child being used in the respone models, but a Child4 class being generated.

Json2CSharp commented 2 years ago

I'll check this issue today, thanks for the heads up

Json2CSharp commented 2 years ago

This is fixed

marblekirby commented 2 years ago

Thanks!