1

I want to validate extension of Multipartfile object. I added @Valid and my custon annotation to parameter @ImageFileValid but it doesn't work.

@PutMapping("/{id}")
ProductDto updateProduct(@RequestPart @Valid ProductDto product, @PathVariable Long id,@RequestPart @Valid @ImageFileValid MultipartFile image) {
    return productMapper.productToProductDto(productService.update(productMapper.productDtoToProduct(product),id));
}
Thilo Schwarz
  • 359
  • 2
  • 17
Mateusz Sobczak
  • 1,284
  • 6
  • 24
  • 52

1 Answers1

1

Very short but clear reference from Spring-Boot, Validation:

The method validation feature supported by Bean Validation 1.1 is automatically enabled as long as a JSR-303 implementation (such as Hibernate validator) is on the classpath. This lets bean methods be annotated with javax.validation constraints on their parameters and/or on their return value. Target classes with such annotated methods need to be annotated with the @Validated annotation at the type level for their methods to be searched for inline constraint annotations.

So, please annotate (the containing) controller class with @Validated & report if any issues.


A sample repo at github.

xerx593
  • 8,962
  • 5
  • 27
  • 53