CodeWarrior
CodeWarrior

Reputation: 354

Spring Boot Bean Validation In HashMap Not Working

I am creating a REST controller which shall take a list of Dtos. It all works but the validation is not working, therefore it fails during persistence only.

My code:

@Valid @RequestBody HashMap<String, MyDto> myDtoMap

And unfortunately the MyDto does not get validated.

I also tried this way:

@Valid @RequestBody HashMap<String, @Valid MyDto> myDtoMap

Upvotes: 0

Views: 330

Answers (1)

Tung Phan
Tung Phan

Reputation: 66

Please try :

annotate your controller with :

@RestController
@Validated

Then you can validate you class with :

@RequestBody HashMap<String, @Valid MyDto> myDtoMap

Upvotes: 4

Related Questions