0

I followed these two links/tutorials:

a) Spring MVC: How to perform validation?

b) https://g00glen00b.be/validating-the-input-of-your-rest-api-with-spring/

It works fine except for one thing. Eventhough my controller is annotated with @RestController the response I get is HTML, unlike the JSON response shown in the tutorial.

Questions:

  1. Which component/bean is the "culprit" which builds and returns the HTML response?
  2. How to make it return a response body instead of a view?
  3. How to override this component with a custom one?

Best! Pawel

Pawel Os.
  • 611
  • 8
  • 26
  • Ok, I found the answer to 1): DefaultHandlerExceptionResolver 2 and 3) You implement an own ExceptionResolver annotated with @ControllerAdvice – Pawel Os. Oct 16 '17 at 13:11
  • Did you send the `Content-Type: application/json` header? The default Spring exception handler will format your response to either HTML/JSON/... depending on the output you want. – g00glen00b Oct 16 '17 at 13:40
  • Cool, I got a response from g00glen00b her or himself ;-) After all I implemented my own ExceptionResolver (which is also described in your tutorial) to handle it. And it returns a response body, so - problem solved! Thanks – Pawel Os. Oct 17 '17 at 08:48

0 Answers0