Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:45:33+00:00 2026-05-23T22:45:33+00:00

I’m trying to use MappingJacksonJsonView with Spring 3.0, without success. I don’t know what

  • 0

I’m trying to use MappingJacksonJsonView with Spring 3.0, without success. I don’t know what I’m doing wrong, I think the problem is that I don’t know how to tell to use the MappingJacksonJsonView to render a request. I tried to use the same name for view name and bean name of MappingJacksonView, but didn’t work. I built a sample test application here: https://github.com/stivlo/restjson

In web.xml I’ve defined ContextLoaderListener and the mapping for dispatcherServlet.

In servlet-context.xml I’ve added

<mvc:annotation-driven/>

and

<bean name="jsonView"
    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>

In org.obliquid.restjson.web.ToDoList.java I set the logical view name as jsonView.

However, instead of using MappingJacksonJsonView, it looks for a JSP file, according to my JSP mapping.

message /restjson/WEB-INF/jsp/jsonView.jsp
description The requested resource (/restjson/WEB-INF/jsp/jsonView.jsp) 
    is not available.

What should I change to use MappingJacksonJsonView as a renderer?

UPDATE 1: In following tests I’ve found that if I add the following to my servlet-context.xml, JSON rendering works, but my other view, rendered as JSP (home) is not working anymore.

<!-- Resolve views based on string names -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

UPDATE 2: I removed the BeanNameViewResolver and changed my ToDoList.java to return directly the Collection to be converted in JSON, instead of ModelAndView, with a @ResponseBody annotation, as follows:

@RequestMapping("/toDoList")
public @ResponseBody List<ToDoItem> test() {
    List<ToDoItem> toDoList = new ArrayList<ToDoItem>();        
    toDoList.add(new ToDoItem(1, "First thing, first"));
    toDoList.add(new ToDoItem(1, "After that, do the second task"));
    return toDoList;
}

In this way it works. Even though the mapping is even more “magical”. It makes me wonder, if a similar renderer exists for XML for instance, how does Spring know which renderer to pick?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:45:33+00:00Added an answer on May 23, 2026 at 10:45 pm

    Spring will use Accept header sent by the client to return most appropriate view. Here you will find my complete Spring MVC application that returns both JSON and XML.

    As you can see, I only needed:

    <mvc:annotation-driven />
    

    I also used the same annotations: @RequestMapping to map request to a method and @ResponseBody to tell Spring that what I am returning from the controller is the actual response. It might however need some tweaking/formatting, and here Spring takes care of marshalling your object into most appropriate type like JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.