java - Spring Jackson @JsonFilter 示例

标签 java json spring spring-mvc jackson

有谁知道在 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/

相关文章:

java - 将 Kafka Streams 与 Avro 架构注册表结合使用

java - 存储库中缺少 bean

javascript - 我如何使用 JavaScript 转义 JSON 字符串中的 Unicode 字符?

python - 使用 json 验证使用 python 显示 json 模式中的所有错误

javascript - 如何在此 JSON 响应中访问 browser 和 browser_version?

spring - 为什么@Transactional 会自动保存到数据库

java - 如何将 Arraylist<ArrayList<objects>> 转换为 ArrayList<objects>

java - 从 Java Servlet 委派工作负载

java - spring 事务期间 autocommit=true

java - 在 tomcat 中部署 Spring Boot war 时,application.yml 文件应该放在哪里?