【问题标题】:@JsonView how to use with @RequestBody@JsonView 如何与 @RequestBody 一起使用
【发布时间】:2015-08-30 01:06:26
【问题描述】:

我想添加 JsonView 功能来控制我的应用程序的输入。而且我发现我可以在 Spring 4.1.0.RELEASE 中将此注释与 RequestBody 一起使用,但会出现错误 this annotation not allowed here

 public ResponseEntity<User> update(@RequestHeader(value="Access-key") String accessKey,
                                         @RequestHeader(value="Secret-key") String secretKey,
                                         @JsonView(View.Summary.class) @RequestBody User user) throws Exception{

【问题讨论】:

  • 您使用的是什么版本的 Jackson?根据 this GitHub issue @JsonView 自 2.5 起支持方法参数。这个Spring issue 也表明它是在 Spring 4.2.RC1 而不是 4.1 中实现的。
  • @BohuslavBurghardt 2.2.3,现在我将其更改为 2.5,它会有所帮助。谢谢

标签: java spring-mvc jackson


【解决方案1】:

@JsonView 注释自 Jackson 2.5 版起支持方法参数。因此,您必须升级您的 Jackson 依赖项才能使其正常工作。

来源:Github

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 1970-01-01
    • 2020-02-12
    • 2013-08-20
    • 1970-01-01
    • 2011-09-02
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多