I got the following function in my REST Java service running in a Glassfish Server:
serviceTest.java
@Path("/servicetest")
public class serviceTest{
@GET
@Path("/findall")
@Produces(MediaType.APPLICATION_JSON)
public List<Person> findAll(){
List <Person> result = new ArrayList<>();
result.add(new Person("1", "Charlie");
result.add(new Person("2", "Mary");
return result;
}
}
Also I have defined a class:
person.java
public class person {
private String id;
private String name;
public person(String id, String name) {
this.id = id;
this.name = name;
}
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;
}
}
When I called the findAll() function from the client side or a web browser, I'm getting the following JSON object in this format:
[
{
"id": "1",
"name": "Charlie"
},
{
"id": "2",
"name": "Mary"
}
]
But I need to identify the JSON array by a name, something like this:
{"person":
[
{
"id": "1",
"name": "Charlie"
},
{
"id": "2",
"name": "Mary"
}
]
}
How can I do this...? Thanks in advance...