@ControllerAdvice fails in returning ResponseEntity<T> (T is a POJO) @ControllerAdvice fails in returning ResponseEntity<T> (T is a POJO) json json

@ControllerAdvice fails in returning ResponseEntity<T> (T is a POJO)


I do not know what exactly the answer is but maybe the problem is with JSON configuration. At first your @Controller is not @RestController and you are not specifying explicitly what is produced. I hope you do this in your request, so spring knows what to do. I think the mime type from @Controller is inherited and used to conversion.

You may try to add a breakpoint in your http message converter. In every converter there is a mathod supports try to catch your code here. Check which converter is returning true. Spring uses the first one if more than one passes the conditions. Going up through the stacktrace you may also find which converters are available for your request and what kind of converter is required.

http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/AbstractHttpMessageConverter.html#supports-java.lang.Class-


Based on the log you have attached:

  1. you try to request a resource /wackend/swagger-ui.html
  2. you have DefaultController that handles all requests

What you need to do:

  1. Read and configure Swagger properly: https://www.concretepage.com/spring-4/spring-rest-swagger-2-example
  2. Add JSON library to support marshling: