I have gone through other similar asked questions but nothing worked for me.
All my API\'s return JSON as response by Default:
For me, adding
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8);
}
}
solved the problem.
Now by default all RestController
s return JSON, if no Accept
header in the request.
Also if Accept: application/xml
header is passed, then result is XML.
Also, worth reading: https://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc