Validation does not kick in when posting to RestController. Very simple application setup with springboot-starter-validation added to build.gradle. Code is written in Groovy.
Entitiy to be validated:
@Entity
@Table(name = "event")
class Event extends Base {
@Column(nullable = false, unique = true)
@NotBlank
String name
}
Controller:
@RestController
class ApiController {
@Autowired
EventService eventService
@PostMapping("/api/event")
Event createEvent(@Valid @RequestBody Event event) {
eventService.save(event)
}
}
When posting simple json: {"name": ""}to the endpoint "/api/event" I would expect that Spring would throw MethodArgumentNotValidException but the entity is saved with "" as a value for name. Adding BindingResult as parameter to createEvent yield 0 binding errors.
I must be missing something. But I can't spot what it is. Can you? :)
@Validatedannotation is validation groups... It did not do the trick.. :)