Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3655

How to return multiple field validation violations (`jakarta.validation.constraints`) in Spring Boot REST API?

$
0
0

The context:

I have a REST API in my Spring Boot backend app. This REST API has HTTP POST endpoint with a request body. This request body as a java DTO class contains several fields (attributes). I added jakarta.validation.constraints annotations like @NotNull@NotEmpty and others to these fields to validate input data.

Now:

If any of these fields violate these jakarta.validation.constraints annotations constraints it immediately throw an exception which of course I catch with ExceptionHandler class which return HTTP 400 Bad Request with the proper error message. The issue is that with that approach I cannot provide all fields validation violations to user to give the user the whole understanding which fields input are incorrect which are correct because an exception is thrown after just validation first wrong input.

I need:

I need that I have opportunity to send the user an error message with all all fields validation violations.


My app has:

  • org.springframework boot 3.2.5 version

  • java 17


Viewing all articles
Browse latest Browse all 3655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>