I am using dropwizard which uses jersey & jackson for json. My issue is when I return a list it does not specify a root.
I have a POJO class:
public class Company {
public String id;
public String name;
public String address;
}
and my resource is set up thus:
@GET
@Path("/companies/all")
public List<Company> getAllCompanies(){
...
return companies;
}
And I get the following response:
[{
"id": "01",
"name": "Yammer Corp",
"address": "1 Finite Loop"
},
{
"id": "02",
"name": "DropWizards Inc",
"address": "4 Magic Square, Olympus"
}]
While what I want is something like below:
{"Companies" :
[{
"id": "01",
"name": "Yammer Corp",
"address": "1 Finite Loop"
},
{
"id": "02",
"name": "DropWizards Inc",
"address": "4 Magic Square, Olympus"
}
]}
Any ideas? Thanks in advance.
You need to create one more POJO wrapping the
List<Company>The Change required in your GET Method is: