How to write a java tree Structure and Serializer / Deserializer to Json

advertisements

I use spring framework.

I want to implements Java tree structure and Serializer/Deserializer to JSON.

like below JSON,

 [
        {"id":"1","pid":"0","name":"n1", "chindren":[
            {"id":"4","pid":"1","name":"n4", "chindren":[
                {"id":"7","pid":"4","name":"n7", "chindren":[
                    {"id":"15","pid":"7","name":"n15"}

                ]},
                {"id":"8","pid":"4","name":"n8"},
                {"id":"9","pid":"4","name":"n9"},
                {"id":"10","pid":"4","name":"n10"}
            ]},
            {"id":"5","pid":"1","name":"n5","chindren":[
                {"id":"19","pid":"5","name":"n19"},
                {"id":"20","pid":"5","name":"n20"}
            ]}
        ]},
        {"id":"2","pid":"0","name":"n2","chindren":[
            {"id":"13","pid":"2","name":"n13"}

        ]},
        {"id":"3","pid":"0","name":"n3","chindren":[
            {"id":"11","pid":"3","name":"n11"},
            {"id":"12","pid":"3","name":"n12"}
        ]}
    ]

How to convert above JSON tree to a Java class and Serializer/Deserializer to JSON


Here you can use jackson libs with your spring frame work to convert json to java classes and vice versa. For more information about jackson see this

To generate java pojo classes use this online tool click here

hope it will help you.