Announcement Announcement Module
No announcement yet.
Spring MVC Jabx2 ResponseBody with generic List Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC Jabx2 ResponseBody with generic List

    Hi there,

    I'm very pleased by the possibilities given by Spring MVC in term of RESTFul capabilities, but I missed something talking about ResponseBody conversion.

    Why can't we deal with List<?> the same way with JSON or XML conversion.

    For instance, the Jackson converter will happily transform a list of Person (with a name field) in :
    [{name: 'person1'}, {name: 'person2'}]

    But the Jaxb converter will not be able to convert this List because List don't provide the @XmlRootElement. So I need to explicitly wrap my list in a wrapper object. From my point of view, this break the contract between Controller and View (rendering), because the Controller dedicate the return type for a specific ContentType acceptance.

    I read something quite interesting here

    Maybe the Jaxb2RootElementHttpMessageConverter could be modified in order to provide such a fallback on generic type. Does it make sense ?