@Valid
annotation is not calling validator when @RequestPart
is used. In other places I used @Valid
with @RequestBody
and it works fine.
There is no error just passing the wrong validation also.
Below is the code.
@InitBinder("campaignCreatorDTO")
public void initCreatorDTOBinder(WebDataBinder binder) {
binder.addValidators(new CreatorDTOValidator());
}
@PostMapping(value = "/creator", consumes = {"multipart/form-data"}, produces = {"application/json"})
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
public @Valid
ResponseDTO creator(@Valid @RequestPart("json") CampaignCreatorDTO campaignCreatorDTO,
@RequestPart(name = "file", required = false) MultipartFile adGraphic) {
}