How to get this type of structure response in json using java(Spring)

60 Views Asked by At

I want to get all the stories and its substories from backlog using java.

{ stories :
          [
             code du story : 11245;
             title du story : "title1";
             .....
          ] ,
          [ 
             code du story : 212458,
             title du story : "title2";
             .....
                    substories : [
                                    code: 4583 ; title: ”lib3” …. 
                                 ],
                                 [ 
                                    code: 124584 ; title: ”lib4” 
                                 ], …
          ],
          [
             code du story : 12845;
             title du story : "title5";
             .....
          ] ,
          ....

I tryed :

List<List<Object>>

But it doesn't work for me

How to do like this response structure and return it in json?

Thanks in advance.

1

There are 1 best solutions below

1
Saurabh Nigam On

Make classes to serialize and deserialize objects in java Use objectmapper to to convert from object to string and vice versa. You can use object mapper in Jackson library.

Code example

  Class Stories{
       String code;
       String title;
       List<Stories> subStories;
    }

   ObjectMapper mapper = new ObjectMapper();

   List<Stories> stories =  mapper.readValue(jsonstring, new TypeReference<ArrayList<Stories >>() {});
}