Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7344

Spring Portlet MVC - Unable to return JSON data from @ResourceMapping

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Works as Designed
    • Affects Version/s: 3.0.3
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      In many scenarios it is required to support returning JSON data from the @ResourceMapping annotated method of controller. The @ResponseBody and ContentNegotiatingViewResolver currently work only in the servlet environment.

        Issue Links

          Activity

          Hide
          koptan Abdulrhman Nabih ALKoptan added a comment -

          Any Update ?

          Show
          koptan Abdulrhman Nabih ALKoptan added a comment - Any Update ?
          Hide
          rogge Patrick Bergner added a comment -

          Happy new year, portlet people! Will we see the feature in the currently set 4.2 fix version or will it be bumped further and further?

          Show
          rogge Patrick Bergner added a comment - Happy new year, portlet people! Will we see the feature in the currently set 4.2 fix version or will it be bumped further and further?
          Hide
          kart Ram Chinnakuzhandai added a comment -

          Can we have this feature to be part of upcoming release + 1, at least. This has been sitting in the rack for a long time, and would be a huge help for the portlet community.

          Show
          kart Ram Chinnakuzhandai added a comment - Can we have this feature to be part of upcoming release + 1, at least. This has been sitting in the rack for a long time, and would be a huge help for the portlet community.
          Hide
          sdeleuze Sébastien Deleuze added a comment -

          Hi everybody,

          While working on this issue, I figured out that rendering JSON data from @ResourceMapping is already possible out of the box (tested with Spring 3.2.6.RELEASE and 4.2.0.BUILD-SNAPSHOT) using MappingJackson2JsonView:

          	@ResourceMapping("json")
          	public ModelAndView listBooksJson() {
          		ModelAndView mav = new ModelAndView();
          		mav.addObject("books", bookService.getAllBooks());
          		mav.setView(new MappingJackson2JsonView());
          		return mav;
          	}

          You can test this sample application and have a look to this commit that introduced such functionality in the sample application.

          While this is not @ResponseBody support, the MappingJackson2JsonView alternative is really easy to use with @ResourceMapping and seems to me a reasonable solution for the need expressed here. Could anybody interested give it a try and send us some feedbacks to confirm it works as expected (or to report any issue)?

          Thanks in advance for your feedbacks.

          Show
          sdeleuze Sébastien Deleuze added a comment - Hi everybody, While working on this issue, I figured out that rendering JSON data from @ResourceMapping is already possible out of the box (tested with Spring 3.2.6.RELEASE and 4.2.0.BUILD-SNAPSHOT) using MappingJackson2JsonView : @ResourceMapping ( "json" ) public ModelAndView listBooksJson() { ModelAndView mav = new ModelAndView(); mav.addObject( "books" , bookService.getAllBooks()); mav.setView( new MappingJackson2JsonView()); return mav; } You can test this sample application and have a look to this commit that introduced such functionality in the sample application. While this is not @ResponseBody support, the MappingJackson2JsonView alternative is really easy to use with @ResourceMapping and seems to me a reasonable solution for the need expressed here. Could anybody interested give it a try and send us some feedbacks to confirm it works as expected (or to report any issue)? Thanks in advance for your feedbacks.
          Hide
          sdeleuze Sébastien Deleuze added a comment -

          Since there are no feedback more than one week after my last comment, I resolve this issue as "Works as designed" since it is already possible to return JSON in Portlets using ModelAndView and MappingJackson2JsonView.

          Supporting also ResponseBody would require a lot of changes, with little added value so I think the current solution is a reasonable one.

          Show
          sdeleuze Sébastien Deleuze added a comment - Since there are no feedback more than one week after my last comment, I resolve this issue as "Works as designed" since it is already possible to return JSON in Portlets using ModelAndView and MappingJackson2JsonView . Supporting also ResponseBody would require a lot of changes, with little added value so I think the current solution is a reasonable one.

            People

            • Assignee:
              sdeleuze Sébastien Deleuze
              Reporter:
              ashes.sarin Ashish Sarin
              Last updater:
              Sébastien Deleuze
            • Votes:
              60 Vote for this issue
              Watchers:
              46 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                15 weeks, 2 days ago