views:

115

answers:

1

Title pretty much says it all. Right now it's using XML as the default in the responses from my controller but I want it to use JSON as the default when no Accepts header or format parameter is specified.

My mvc-config.xml

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="mediaTypes">

        <map>
            <entry key="html" value="text/html" />
            <entry key="json" value="application/json" />
            <entry key="xml" value="application/xml" />
        </map>
    </property>
    <property name="defaultViews">
        <list>
            <bean class="com.work.web.view.json.ExtendedMappingJacksonJsonView">
                <property name="objectMapper">
                    <ref bean="JacksonObjectMapper" />
                </property>
            </bean>
            <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                <property name="marshaller">
                    <ref bean="Jaxb2Marshaller" />
                </property>
            </bean>
        </list>
    </property>
    <property name="favorParameter" value="true" />
</bean>

<bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <bean
                class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="objectMapper">
                    <ref bean="JacksonObjectMapper" />
                </property>
            </bean>
            <ref bean="marshallingHttpMessageConverter" />
        </list>
    </property>
</bean>

<bean id="marshallingHttpMessageConverter"
    class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    <property name="marshaller" ref="Jaxb2Marshaller" />
    <property name="unmarshaller" ref="Jaxb2Marshaller" />
</bean>
<bean id="JacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<bean id="JacksonSerializationConfig" class="org.codehaus.jackson.map.SerializationConfig"
    factory-bean="JacksonObjectMapper" factory-method="getSerializationConfig" />
<bean
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" ref="JacksonSerializationConfig" />
    <property name="targetMethod" value="setSerializationInclusion" />
    <property name="arguments">
        <list>
            <value type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion">NON_NULL</value>
        </list>
    </property>
</bean>
<bean id="Jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>com.work.Concepts</value>

        </list>
    </property>
</bean>
A: 
<property name="defaultContentType" value="application/json" />

when setting up ContentNegotiatingViewResolver bean

AHungerArtist