How to set default output to JSON for REST?


I have attached ‘com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.9’ to project and received wrong behaviour with REST.

Now if I send request to REST without Accept header ‘application/json’ response is with XML.
For example:

Produce such XML response:

    <error_description>Bad credentials</error_description>

When I add header Accept. There is OK, response is JSON.

How to change default content type for REST, if not specified Accept header?

In SO recommends
public class WebConfig extends WebMvcConfigurerAdapter {

    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {


Is this can help me? Or may be we can change default content by application properties?

Attaching sample project with such problem. (91.1 KB)

right now the option I see is to configure the content negotiation manager in the rest-dispatcher-spring.xml file. We’ve created the issue - the JSON content type will be default. Until the issue is solved you can do the following:

  1. In the web module create the first-rest-dispatcher-spring.xml file that registers the content negotiation manager:
<beans xmlns=""

    <bean id="contentNegotiationManager"
        <property name="defaultContentType" value="application/json"/>

    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
  1. Register the file in the file:
cuba.restSpringContextConfig = com/company/testxml/first-rest-dispatcher-spring.xml com/haulmont/cuba/rest-dispatcher-spring.xml

Note that there is no + sign there and your file is registered before the com/haulmont/cuba/rest-dispatcher-spring.xml of CUBA.

Here is the zip archive with your sample project where these modifications are done: (97.1 KB)

@gorbunkov Max, thank you for your solution. I’ll use it in the future.

Another solutuion is add header by reverse proxy. My app is under reverse proxy Nginx and I added this header for workaround.
Thank you!

Max, thank you for your solution. I’ use it in the future. Now I solved problem by adding this header in Nginx reverse proxy.