【发布时间】:2012-06-20 22:45:07
【问题描述】:
我正在使用 Spring MVC Annotations 创建一个 JSON Rest API,其方法定义如下:
@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public @ResponseBody AuthenticationResponse authenticate(@RequestBody final DeviceInformation deviceInformation)
throws AuthenticationException {
return createAuthenticationResponse(deviceInformation, false);
}
为了处理不同的客户端版本,我想通过使用类似注释来排除或包含序列化 bean 的属性
class AuthenticationResponse {
@InterfaceVersion(max = 2)
String old;
@InterfaceVersion(min = 3)
String new;
}
因此,如果客户端使用 InterfaceVersion 2 调用,他将不会获得 new 属性,如果他使用 3 调用,他将不会获得 old 属性。
我已经发现 Jackson 库(Spring 用于 JSON)提供了 JsonView、JsonFilter 等功能,但我不知道我必须在哪里以及如何配置这些东西。
【问题讨论】:
标签: json spring-mvc jackson