【发布时间】:2017-09-27 15:51:10
【问题描述】:
当我发布到我的控制器时,我遇到了可清除异常的问题 - 带有 null 的 json。
Ive set all fields as @NotNull. And its 工作正常(哪些 null 值我看到了很好的异常消息:字段 '' 上的对象 '' 中的字段错误:拒绝值 [null])。
很遗憾,使用 @NotNull 收集字段会返回 JsonMappingException。
例如:
@Value
public final class User {
@NotNull
private final Integer age; //work fine
@NotNull
private final List<Books> books; //doesn`t work
我ve also tried with @Valid and @NotEmpty, but it didnt 帮助。
我的控制器方法:
@Timed
@ExceptionMetered
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@PreAuthorize("@auth.hasAccess(...)")
void registerUser(@RequestBody @Valid User user) {
userService.registerUser(user);
}
你知道它有什么问题吗?
【问题讨论】: