【发布时间】:2013-01-23 20:26:21
【问题描述】:
我正在使用 dropwizard,它使用 jersey 和 jackson 作为 json。我的问题是当我返回一个列表时它没有指定根。
我有一个 POJO 类:
public class Company {
public String id;
public String name;
public String address;
}
我的资源是这样设置的:
@GET
@Path("/companies/all")
public List<Company> getAllCompanies(){
...
return companies;
}
我得到以下回复:
[{
"id": "01",
"name": "Yammer Corp",
"address": "1 Finite Loop"
},
{
"id": "02",
"name": "DropWizards Inc",
"address": "4 Magic Square, Olympus"
}]
虽然我想要的是如下所示:
{"Companies" :
[{
"id": "01",
"name": "Yammer Corp",
"address": "1 Finite Loop"
},
{
"id": "02",
"name": "DropWizards Inc",
"address": "4 Magic Square, Olympus"
}
]}
有什么想法吗?提前致谢。
【问题讨论】:
-
你需要再包装一个 POJO。
标签: java jersey dropwizard