我需要手动在POST方法中验证带有@NotBlank
注释的Resource对象。有没有办法使用Jackson / Spring api验证Resource对象。不知道怎么做。
public class FileMetadataResource extends BaseResource {
@JsonProperty("title")
@NotBlank(groups = {default.class})
@Size(max = 60)
private String title;
@JsonProperty("description")
@Size(max = 255)
@NotBlank
private String description;
}
我的自定义HandlerMethodArgumentResolver
填充了FileMetadataResource
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/related")
@ResponseStatus(HttpStatus.CREATED)
public FileMetadataResource post(FileMetadataResource fileMetadataResource) {
//How to validate fileMetadataResource using jackson here
}
感谢任何帮助。