小编Mas*_*bha的帖子

@JsonIgnoreProperties(ignoreUnknown=false) 在 Spring 4.2.0 及更高版本中不起作用

@JsonIgnoreProperties(ignoreUnknown=false) 不适用于 spring 4.2.0 和更高版本的 spring。但它适用于 4.0.4 和 4.0.1 。我正在使用 spring 4.2.8 并使用 Jackson 依赖项

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.6.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.6.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.6.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

如果我发送带有无效字段的 json 请求,那么它会作为有效请求接受。但它应该给出错误的请求作为响应。例如:如果我有课

public class Student{ 
    private String id; 
    private String name; 
}
Run Code Online (Sandbox Code Playgroud)

如果发送有效的相应 json 请求,它应该是这样的

{ 
   "id": "123", 
   "name": "test" 
}
Run Code Online (Sandbox Code Playgroud)

但即使我发送带有无效字段的 json 请求,如下所示,它仍然接受。

{ 
    "id": "123", 
    "name": "test", 
    "anyinvalidkey": "test" 
}
Run Code Online (Sandbox Code Playgroud)

但它应该给出错误的请求作为响应

spring spring-mvc jackson-dataformat-xml jackson2

6
推荐指数
2
解决办法
8308
查看次数