• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpMessageConverter for @RequestBody and @ResponseBody

 
H Paul
Ranch Hand
Posts: 471
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While troubling shooting/debug the error:

I came across these 3 below classes:

Why on the client side, RestTemplate has all HttpMessageConverter registered with 3 jaxb, json and rome optional
and
Why on the server side, RequestMappingHandlerAdapter or AnnotationMethodHandlerAdapter do not have all or rather defined as RestTemplate?


 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using the RequestMappingHandlerAdapter now so I will only comment on that one. There are no advantages to using the older AnnotationHandlerMethodAdapter.

If you use the @EnableWebMvc in an @Configuration class or if you use the <annotation-driven/> tag in the MVC namespace (if you are using XML for configuration) then Jaxb2RootElementHttpMessageConverter, MappingJackson2HttpMessageConverter, MappingJacksonHttpMessageConverter, AtomFeedHttpMessageConverter, and RssChannelHttpMessageConverter will be registered automatically if the correct classes are present on the classpath. Alternatively you can extend WebMvcConfigurationSupport and override this behaviour among others in any way you see fit. This is true at least in spring 3.1.3-RELEASE and I assume other variations of 3.1.x as well (and 3.0.x as well if I recall)


In Spring 3.2 it was added as well to the default constructor of RequestMappingHandler adapter (where you were previously looking) in the form of an AllEncompassingFormHttpMessageConverter. Either way though assuming you are using the annotation or XML tag to initialize things they are getting registered. If you are manually wiring up your RequestMappingHandlerAdapter (totally unnecessary in most cases) then depending what your configuration looks like you may need to set explicity all the type converters you want registered.


This is the default constructor in 3.2.0 (note the absence of this in 3.1.x does not mean they were not getting registered. It happens in the bean definition parser or WebMvcConfigurationSupport depending on whether you are using XML or annotations to bootstrap your MVC stuff)


HTH
 
H Paul
Ranch Hand
Posts: 471
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill. See reply in your above mentioned thread.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic