• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

HttpMessageConverter for @RequestBody and @ResponseBody

 
Ranch Hand
Posts: 491
5
  • 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?


 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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: 491
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill. See reply in your above mentioned thread.
    Bookmark Topic Watch Topic
  • New Topic