我们需要删除这种返回中的基列表对象(equipmentMetrics):
{
"equipmentMetrics": [{
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-10-10"
}, {
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-11-10"
}]}
我们使用的是泽西岛和这个对象:
@XmlRootElement(name = "equipmentMetrics")
public class EquipmentMetricsResponse {
private String id;
...}这个端点:
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("")
public List<EquipmentMetricsResponse> postV1Default(EquipmentMetricsRequest theRequest) {...}我相信我们希望反应是这样的。我们只想拿出:
"equipmentMetrics":
所以我相信我们希望这样:
[{
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-10-10"
}, {
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-11-10"
}]有什么帮助吗?
发布于 2012-11-15 20:34:48
您可以使用com.google.gson.Gson库来完成它。
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("")
public String postV1Default(EquipmentMetricsRequest theRequest) {
List<EquipmentMetricsResponse> retVal ...
...
return new Gson().toJson(retVal);
} 返回的JSON
[{
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-10-10"
}, {
"id": "BOSS|C5E02126",
"reportedHours": "499.9998",
"reportingDate": "2012-11-10"
}]https://stackoverflow.com/questions/13403692
复制相似问题