views:

63

answers:

1

In spring mvc 3.0, how can I set the content type of a particular action?

I want to set the action to return a json result.

+2  A: 

In Spring 3, you generally don't need or want to set the context type yourself, it's usually unnecessary.

In the case of controllers that need to return JSON, the simplest way to return JSON is to return an instance of MappingJacksonJsonView from your handler method. This will set the content-type for you. Jackson now has built-in support in Spring 3.

skaffman
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ I just stumbled upon this article, might be useful as well.
Bozho
Yeah, I spotted that this morning... `@ResponseBody` is very nice :)
skaffman