1

I have a Java servlet sending JSON with jackson/jersey. I have to send a tree. This is my data structure.

public class Node {
    private String text;
    private String link;
    private List<Node> items;

    [...]
}

i.e i request / I want the first level only, answer should be :

    {
        "text":"toto",
        "link":"",
        "items":[{
            "text":"toutou",
            "link":"tata",
        ]}
    }

and if i request /tata answer should be :

    {
        "text":"toutou",
        "link":"tata",
        "items":[{
            "text":"toto2",
            "link":"toutou2",
        ]}
    }

So i only want to send 1 level of items because otherwise the JSON would be too big. Is it possible ?

Thanks,

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
Cuva
  • 335
  • 1
  • 4
  • 15

1 Answers1

0

Your question interested me so I started searching for recursive bean reference and how to avoid it using Jackson.

I found this answer. I have not tried it, but it seems approved and appraised. Maybe it is worth trying. Please write back what happened, because I am also interested in the results.

Community
  • 1
  • 1
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • I'm afraid the first part of his answer is more about bi directional relationship than my problem. Whereas implementing a custom module for serialization/deserialization I would have hope there was a simpler way, kinda of a dynamic JsonIgnore... – Cuva Dec 02 '12 at 11:21
  • If you can formulate your requirement as a feature to implement, maybe file an RFE for Jackson? – StaxMan Dec 03 '12 at 21:48