Skip to content
Sharp

Spring Core · interview question

In Spring Boot, how can you validate the fields of a request body in a REST controller?

Multiple choiceMediumchapter-9-curatedpremiumspring-corepersistence-and-validation
Choose one answer
Answer and explanation

Correct answer

C. Use @Valid with @RequestBody

Why

To validate the fields of a request body, you can use @Valid in combination with @RequestBody. This triggers validation of the object's fields based on the constraints specified.

Test yourself on Spring Core

A free test with instant, explained results. No account needed.

Start free test
All Spring Core questions →