jackson's @JsonIdentityInfo with breadth first

391 views Asked by At

I am using Jackson's @JsonIdentityInfo for removing circular objects from JSON.

Suppose following is Java Classes Class A, B, C and following is structure,

Class A{
     int id;
     B b;
     C c;
}
Class B{
     int id;
     C c;
}

My object is (A)

{
     id:1,
     b:{
          id: 2,
          c:{
            id: 3
            }
     },
     c: {
        id: 3
     }
}

It is changing object to

{
         id:1,
         b:{
              id: 2,
              c:{
                id: 3
                }
         },
         c: 3
    }

Because C has same id, I want this to be implemented as Breadth first i.e. first level should be remove object and give property but depth level should do this, is there a way to get it like following?

{
             id:1,
             b:{
                  id: 2,
                  c:3
             },
             c: {id:3}
        }
1

There are 1 answers

0
StaxMan On

No, serialization proceeds depth-first, and changing that would require potentially buffering the whole output graph in memory before writing JSON.