我有以下代码:
@GET
@Path("v1/entity")
@ApiOperation(
value = "List",
notes = "Enables you to List.",
tags = { "List" })
@ApiImplicitParams(
{
@ApiImplicitParam(name = "pageSize",
value = "Page Size",
dataType = "int",
paramType = "formData",
example = "50"),
@ApiImplicitParam(name = "sortAscending",
value = "Sort Ascending",
dataType = "boolean",
paramType = "formData",
example = "false")
})
public Response list(@ApiParam(hidden = true) Integer pageSize,
@ApiParam(hidden = true) Boolean sortAscending) {
Collection<EntityData> dataCollection;
if (pageSize == null || sortAscending == null || pageSize <= 0) {
dataCollection = storeController.list();
} else {
SortDirection sortDirection = sortAscending ? SortDirection.ASC : SortDirection.DESC;
dataCollection= storeController.list(pageSize, sortDirection);
}
logger.info("List contains {} elements", dataCollection.size());
GenericEntity<Collection<EntityData>> response = new GenericEntity<Collection<EntityData>>(dataCollection){};
return Response.ok(response).build();
//return ResponseEntity.ok(dataCollection);
}
当我调用 API 时,出现以下错误:
No message body writer has been found for class java.util.ArrayList, ContentType: */*
我也尝试过使用 来Response
检索内容,而不是使用ResponseEntity<Collection<EntityData>>
,但错误仍然存在。ArrayList
就像直接使用中的“ ”一样Response
(不换行GenericEntity
)。
如果我将最后一行更改为return Response.ok().build();
它可以工作,但我需要Collection
检索...logger
表明当我运行时集合有 9 个元素。
我知道我在这里错过了一些东西,但我看不到它。你能帮助我吗?
墨色风雨
相关分类