i am build an json data using springBoot. I want data in another way i'm getting this reponse
[
{
"id": "Spring",
"name": "Spring FrameWork",
"description": "Spring Frame work descreption"
},
{
"id": "java",
"name": "java FrameWork",
"description": "Java Frame work descreption"
},
{
"id": "javascript",
"name": "javascript FrameWork",
"description": "java script Frame work descreption"
}
]
i want reponse like this
"topics":[
{
"id": "Spring",
"name": "Spring FrameWork",
"description": "Spring Frame work descreption"
},
{
"id": "java",
"name": "java FrameWork",
"description": "Java Frame work descreption"
},
{
"id": "javascript",
"name": "javascript FrameWork",
"description": "java script Frame work descreption"
}
]
my spring boot code is:
@RequestMapping("/topics")
public List<Topic> getAllTopics() {
return topicService.getAllTopics();
}
my model of topic:-
public class Topic {
private String id;
private String name;
private String description;
public Topic() {
}
public Topic(String id, String name, String description) {
super();
this.id = id;
this.name = name;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
What i need to add in code so that JSON data should should contain the name of that List. This can be done using JSON data object. But is there any other way? Please answer my question