java Spring Jackson @JsonFilter 示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6170713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:39:27  来源:igfitidea点击:

Spring Hymanson @JsonFilter Examples

javajsonspringspring-mvcHymanson

提问by Deejay

Does anyone know any examples of using Hymanson‘s @JsonFilter annotations in Spring MVC to enable a caller to specify a return type at runtime?

有谁知道在 Spring MVC 中使用 Hymanson 的 @JsonFilter 注释来使调用者能够在运行时指定返回类型的任何示例吗?

I‘ve got a JSON API that I would like to keep simple by offering methods like getEntity, preferably taking some argument or other to define what view of the entity to return.

我有一个 JSON API,我想通过提供像 getEntity 这样的方法来保持简单,最好采用一些参数或其他参数来定义要返回的实体视图。

回答by George Siggouroglou

You can use something like @JsonView annotation. It was not supported on Spring but this issue is solved!
Follow this

您可以使用 @JsonView 注释之类的东西。Spring 不支持它,但是这个问题已经解决了!
按照这个

Add support for Hymanson serialization views

Spring MVC now supports Hymanon's serialization views for rendering different subsets of the same POJO from different controller methods (e.g. detailed page vs summary view). Issue: SPR-7156

添加对 Hymanson 序列化视图的支持

Spring MVC 现在支持 Hymanon 的序列化视图,用于从不同的控制器方法(例如详细页面与摘要视图)呈现同一 POJO 的不同子集。问题:SPR-7156

This is the SPR-7156.

这是SPR-7156

Status: Resolved

Description

Hymanson's JSONView annotation allows the developer to control which aspects of a method are serialiazed. With the current implementation, the Hymanson view writer must be used but then the content type is not available. It would be better if as part of the RequestBody annotation, a JSONView could be specified.

状态:已解决

描述

Hymanson 的 JSONView 注释允许开发人员控制方法的哪些方面被序列化。对于当前的实现,必须使用 Hymanson 视图编写器,但内容类型不可用。如果作为 RequestBody 注释的一部分,可以指定 JSONView 会更好。

Available on Spring ver >= 4.1

适用于Spring 版本 >= 4.1

UPDATE

更新

Follow this link. Explains with an example the @JsonView annotation.

按照这个链接。举例说明@JsonView 注释。