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 7406527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:34:20+00:00 2026-05-29T05:34:20+00:00

I have a Spring rest service using Spring 3.1.0.RELEASE. Here is the relevant code

  • 0

I have a Spring rest service using Spring 3.1.0.RELEASE. Here is the relevant code for the service call in question:

@RequestMapping(value="/{var1}", method=RequestMethod.GET, produces="application/json")
@ResponseBody
public String getSomeStuff(@PathVariable final String var1) {
    return myJsonString;
}

If I call this using the following curl command, it happily returns me my json string with a content-type of application/xml whereas I would expect a 406 based on the Spring 3.1 docs:

curl -v -H "Accept: application/xml" http://localhost:8080/MyServiceSite/myvalue

There is no extra configuration in my app for this service (no serialization), I am returning raw json with no post-processing for the service configured. I’m certain I have missed something, can anyone point out anything I may have missed?

Edit: Here is the documentation I was looking at when attempting to get this working. Specifically section 16.3.2.5. My code is very similar except that their code looks like it assumes config setup to let Spring handle serialization. Perhaps the produces does not work when bypassing the Spring serialization?

Edit: I changed my expectation for the response code. A 415 would indicate I was sending improper content in my request body whereas 406 is proper for having an accept header that doesn’t jive with the content type of the server.

Anyway, I have changed this method do return a Map and added config for it to serialize to json and now if I send an invalid content type from the client I get the proper 406 response. It seems that maybe the “produces” setting is ignored when the output of the method is not being serialized.

  • 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-29T05:34:20+00:00Added an answer on May 29, 2026 at 5:34 am

    The produces condition is new to Spring MVC 3.1 and is only supported with the RequestMappingHandlerMapping and related @MVC support classes, also new in Spring 3.1. My guess is that you’re using the 3.0 @MVC support classes, which do not support the produces condition. Your code otherwise is correct and so are your expectations of what should happen.

    The use of headers=”Accept=application/json” is unnecessary in 3.1. That’s exactly what the produces condition was introduced for.

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

Sidebar

Related Questions

I have a REST web service using spring MVC which is external-facing. I would
We have created RESTful web services using Spring's REST support. We need to call
I have created a REST web service using WCF and use HTTP Post Method.
I have a REST service built using Jersey. I want to be able to
I have a WCF Rest service: [WebHelp(Comment = Sample description for GetData)] [WebInvoke(Method=POST, UriTemplate
I have a Spring MVC and Resteasy based REST service that i need to
I'm using eclipse and I have a java web service (rest jax-rs) I also
I created a new wcf rest service using .net 4. I have created a
I have exposed my REST API service using WCF Service Library and started by
I tried creating a small example using Spring, rest, Hibernate. In order to have

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.