我有一个由控制器控制的Entity列表,我想作为Resource实体列表发送,但是我得到了我不需要的不必要的null属性,有什么办法可以将它们从列表中删除,它只适用于单个实体。
我的实体:
@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class EntityDTO extends ResourceSupport {
private String one;
// rest of the values
}
控制器:
@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE, path = "/all")
public ResponseEntity<Entity> getAllEntity(){
// lot of validations
List<Entity> entityList = entityUseCase.getAllEntity();
// it access the database to get all entity
return ResponseEntity.status(HttpStatus.OK).body((entityList));
}
但是我得到的回复是:
[
{
"one" : "someValue"
"links": [
{
"rel": "self",
"href": "http://127.0.0.1:9797/start/id/0020299421",
"hreflang": null,
"media": null,
"title": null,
"type": null,
"deprecation": null
},
{
"rel": "DELETE",
"href": "http://127.0.0.1:9797/start/id/0020299421",
"hreflang": null,
"media": null,
"title": null,
"type": null,
"deprecation": null
},
{
"rel": "DELETE",
"href": "http://127.0.0.1:9797/start/uuid/d48363e7-d365-405e-82ed-c73a2aa39fe3",
"hreflang": null,
"media": null,
"title": null,
"type": null,
"deprecation": null
}
]
}
]
但是当我尝试仅获得一个值时,我得到了HAL兼容
{
"one":"someValue"
"_links": {
"self": {
"href": "http://127.0.0.1:9797/start/one"
},
"GET": [
{
"href": "http://127.0.0.1:9797/start/id/390"
},
{
"href": "http://127.0.0.1:9797/start/name?name=someName"
},
{
"href": "http://127.0.0.1:9797/start/all"
}
],
"DELETE": [
{
"href": "http://127.0.0.1:9797/start/id/390"
},
{
"href": "http://127.0.0.1:9797/start/id?id=34"
}
]
}
}
我们将不胜感激。