5

Is there any special configuration one must do? or should it work out of the box?

e.g. should I add something like this to make it work?

 <mime-mapping>
    <extension>json</extension>
    <mime-type>application/json</mime-type>
</mime-mapping> 
Eran Medan
  • 44,555
  • 61
  • 184
  • 276
  • Spring MVC will handle the MIME type itself if it's configured properly, but you'll need to tell us about your config before we can advise. – skaffman May 09 '11 at 09:20

2 Answers2

1

If you are trying to make Tomcat serve .json files with the right mime type then yes, you will need to add that mime type declaration to the conf/web.xml file.

If you're serving dynamically generated JSON then it really shouldn't matter: you can set any mime type using the setContentType function.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • I'm trying to accept JSON requests (of type application/json) – Eran Medan May 11 '11 at 03:05
  • Ah. What failure are you seeing? – Femi May 11 '11 at 13:59
  • This question / answer http://stackoverflow.com/questions/5908466/jquery-spring-mvc-requestbody-and-json-making-it-work-together was the cause, and I suspected that I have a mapping issue (I got null instead of a response) but it seems it's not this. so the question can be closed... – Eran Medan May 19 '11 at 04:50
  • make sure to empty your browser cache after restarting! cf. HTTP code shouldn't be 3xx – Mick F Jan 17 '13 at 13:46
0

It seems there is no special configuration, it accepts any application/json requests out of the box, I was suspecting the wrong issue.

See this other question of mine, it has the original issue and the surprising silly solution: JQuery, Spring MVC @RequestBody and JSON - making it work together

Community
  • 1
  • 1
Eran Medan
  • 44,555
  • 61
  • 184
  • 276