Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:05:14+00:00 2026-05-16T18:05:14+00:00

Here is my situation: I have my mvc-config.xml file for my web service set

  • 0

Here is my situation:

I have my mvc-config.xml file for my web service set up to have JSON as the default media type. I also have favorParameter for the ContentNegotiatingViewResolver as true. Additionally, I have useNotAcceptableStatusCode as true so that not accepted formats will return a 406.

My question is: Is there a way, in the config, to trigger the 406 status code when someone passes in an unacceptable format parameter (format=foo)? Or must that be done with code?

Here is the config file:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <bean
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
            </map>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="com.work.stuff.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="defaultContentType" value="application/json" />
        <property name="favorParameter" value="true" />
        <property name="useNotAcceptableStatusCode" 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.stuff.Concepts</value>
                <value>com.work.stuff.Concept</value>
                <value>com.work.stuff.Terms</value>
                <value>com.work.stuff.Term</value>
                <value>com.work.stuff.Namespaces</value>
                <value>com.work.stuff.Namespace</value>
                <value>com.work.stuff.Subsets</value>
                <value>com.work.stuff.Subset</value>
                <value>com.work.stuff.Associations</value>
                <value>com.work.stuff.Association</value>
            </list>
        </property>
    </bean>
</beans>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:05:14+00:00Added an answer on May 16, 2026 at 6:05 pm

    ContentNegotiatingViewResolver doesn’t seem to support such behaviour. For now, I think your best bet is to subclass it and override the getMediaTypeFromParameter() method to throw an exception if the media type is not supported.

    You can throw any RuntimeException from that method, and if you annotate the exception class with @ResponseStatus, you can control the HTTP response code, e.g.

    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    public class FormatNotSupportedException extends RuntimeException {
    }
    

    In the longer term, I strongly encourage you to file an issue with http://jira.springsource.org, asking for such functionality to be added to ContentNegotiatingViewResolver. They should be able to add this as an optional behavioural parameter. It’s requests like these that mean Spring keeps getting better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Spring MVC and have the following situation: In WEB-INF/demoshop-servlet.xml I have
Here is the situation : we have to offer a customer with a web-based
I am working in a MVC pattern situation here. I have index.php as a
Here's my situation: I have been working on an ASP.NET MVC 3 application for
Here's the situation. What I am working with: - ASP.NET MVC 4 Web API
Here is my situation: I have one table that contains a list of drugs
here's the situation: I have a where in every cell all the area has
Here is my situation: I have a C project linking with many libraries (I
Here's the situation I have a webpage which has one drop down called prefer.
Here's the situation: I have a two images that are over 1024 in width

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.