有什么办法可以将 @JsonView 放在带有 QueryResult returnType 的 Controller 方法上吗?

Is there any way to put @JsonView on Controller method with QueryResult returnType?

我有一个 ViewModel 并根据 this post of spring.io 在某些字段上放置 json 注释,如下所示:

public class SurveyViewModel{
    @JsonView(View.Summary.class)
    private Long     id;
    @JsonView(View.Summary.class)
    private String   title;
    private String   description;
    private String   endDate;
    //Here is getters & setters
}

当我从 REST Controller 中检索数据时,如果 return 我的方法类型是 List,json-结果正常:

@RequestMapping(value = "/getAllGrid", method = RequestMethod.GET)
@JsonView(View.Summary.class)
@ResponseBody
public List<SurveyViewModel> getAll{
    return ModelMapper.mapList(iSurveyService.getAll(), SurveyViewModel.class);
}

但是当我对结果应用分页并将此方法的 return 类型更改为 QueryResult 时,json-结果为空:

@RequestMapping(value = "/getAllGrid", method = RequestMethod.GET)
@JsonView(View.Summary.class)
@ResponseBody
public QueryResult<SurveyViewModel> search(String order, int pageNumber, int pageSize) {
    return ModelMapper.mapQueryResult(iSurveyService.getAllGrid(new SearchOption("", order, pageNumber, pageSize)), SurveyViewModel.class);
}

当我使用上述方法对结果应用分页时,pageNumber, totalRecords & pageSize 添加到我的 json 结果,原始数据作为内部 json 对象添加到 entityList,这是我的 QueryResult json 格式 without apply @JsonView:

{
"pageNumber" : 0,
"totalRecords" : 1,
"pageSize" : 10,
"entityList" : [{
        "id" : 1,
        "title" : "survey1",
        "description" : "...",
        "endDate" : "2017/01/18",
        },{
        "id" : 2,
        "title" : "survey2",
        "description" : "...",
        "endDate" : "2016/11/18",
    }]
}

现在我的问题是,有什么方法可以将 @JsonView 放在 QueryResult returnType 的 Controller 方法上吗?

QueryResult 是我用于分页的对象,我通过将 @jsonView 放在 QueryResult class 的属性上来解决我的问题,如下所示:

public class QueryResult<T> {
    @JsonView(View.Summary.class)
    private int pageNumber;
    @JsonView(View.Summary.class)
    private int totalRecords;
    @JsonView(View.Summary.class)
    private int pageSize;
    @JsonView(View.SummaryWithRecipients.class)
    private List<T> entityList = new ArrayList<T>();
    //Here is getters & setters
}