What Is @ResponseBody in Spring Boot? How Return Values Become JSON (HttpMessageConverter), Its Relationship to @RestController, and Why You Get View-Name Resolution or 406 Errors
Learn what @ResponseBody in Spring Boot is, starting from how HttpMessageConverter writes return values to the response body. We confirm in the source code that @RestController combines @Controller and @ResponseBody, and compare applying it per method versus per class. We reproduce common problems with curl and MockMvc and show how to fix them: errors where a missing annotation causes the return value to be treated as a template name, 406 Not Acceptable, and String return values that don't become JSON.