有谁知道在 Spring MVC 中使用 Jackson 的 @JsonFilter 注释来使调用者能够在运行时指定返回类型的任何示例?
我有一个 JSON API,我想通过提供像 getEntity 这样的方法来保持简单,最好采用一些参数或其他参数来定义要返回的实体的 View 。
最佳答案
您可以使用类似@JsonView 注释的东西。 Spring 不支持它,但此问题已解决!
关注this
Add support for Jackson serialization views
Spring MVC now supports Jackon'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
这是 SPR-7156 .
Status: Resolved
Description
Jackson's JSONView annotation allows the developer to control which aspects of a method are serialiazed. With the current implementation, the Jackson 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.
在 Spring ver >= 4.1 可用
更新
关注这个link .以示例说明 @JsonView 注释。
关于java - Spring Jackson @JsonFilter 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6170713/