這是我的實體傑克遜序列化列表實體(加場到根目錄)
@Entity
public class Product extends AbstractBaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
private String id;
private String title;
我的資源
@Path(value = ApiConstant.Urls.PRODUCTS)
public class ProductResource {
@Inject
private ProductService productService;
@GET
@Path(value = ApiConstant.Urls.PRODUCTS)
@Produces(value = MediaType.APPLICATION_JSON)
public List getProducts(){
return productService.findAll();
}
我JSON響應
[ {
"id" : "596b6a02f70a0878590bcf08",
"title" : "test1",
"description" : "description test 1"
}, {
"id" : "596b6b00f70a087b72d377eb",
"title" : "test1",
"description" : "description test 1"
}, {
"id" : "596b6b75f70a087d40f580d5",
"title" : "test1",
"description" : "description test 1"
} ]
我想創建一個計數字段對這樣的列表 中的項目進行計數並將該列表添加到結果字段
{
"count": 3,
"results": [
{
"id" : "596b6a02f70a0878590bcf08",
"title" : "test1",
"description" : "description test 1"
}, {
"id" : "596b6b00f70a087b72d377eb",
"title" : "test1",
"description" : "description test 1"
}, {
"id" : "596b6b75f70a087d40f580d5",
"title" : "test1",
"description" : "description test 1"
} ],
}
我想序列由JPA持續返回商品目錄
您可以創建一個新的類'ProductsWrapper'與'count'和'results'然後在'getProducts'方法創建的這個實例,而是返回它的名單。 – tima