删除生成的json中的前导数组和/或根元素标签

时间:2017-01-31 21:29:37

标签: json jaxb jersey jackson

我生成的json看起来像这样:

{"popularPurchases":[
     {"product":{"id":"123","face":"face1","size":"1","price":"500"},
       "recent":["smith","hambone","someone"]},
     {"product":{"id":"222","face":"face2","size":"2","price":"600"},
       "recent":["john","mary"]}
]}

我的问题是如何摆脱标签“popularPurchases”(包括':')和“产品(包括':')?

我的POJO看起来都一样。这是其中之一:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class PopularPurchase {

    @XmlElement
    private Product product;

    @XmlElement(name="recent")
    private List<String> users;

    public Product getProduct() {
        return product;
    }
    public void setProduct(Product product) {
        this.product = product;
    }
    public List<String> getUsers() {
        return users;
    }
    public void setUsers(List<String> users) {
        this.users = users;
    }   
}

我需要它看起来像这样:

[
  {"id":"123","face":"face1","size":"1","price":"500"},
    "recent":["smith","hambone","someone"]},
  {"id":"222","face":"face2","size":"2","price":"600"},
       "recent":["john","mary"]}
]

我正在使用:

生成JSON
PopularPurchaseResponse ppResponse = new PopularPurchaseResponse();
ppResponse.setPopularPurchases(popularPurchases);       

builder = Response.status(200).entity(ppResponse);

return builder.build();

0 个答案:

没有答案