Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC not able to return JSONArray object Error 406 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring MVC not able to return JSONArray object Error 406

    I am trying to return JSONArray object from my spring mvc controller. But I am getting 406 error on browser. This is an ajax request and I am using jquery to make the request.

    Spring controller method:

    Code:
    @RequestMapping("/getAuthorizedScreensForUser.do")  
    public @ResponseBody JSONArray getAuthorizedScreensForUser(HttpSession session){  
        UserAuthDetails userAuthDetails = (UserAuthDetails) session.getAttribute("userauthdetails");  
       //This method returns JSONArray  
        return webUtilsService.getJSONArrayResponseForAuthorizedScreens(userAuthDetails.getScrnfldacss());   
    }
    I have tried both these entries in spring-context.xml

    Code:
        <mvc:annotation-driven>  
            <mvc:message-converters>  
                <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">  
                    <property name="prefixJson" value="true"/>  
                </bean>  
            </mvc:message-converters>  
        </mvc:annotation-driven>
    and

    Code:
    <mvc:annotation-driven/>
    My pom.xml has these dependencies:

    Code:
    <dependency>  
                <groupId>org.codehaus.jackson</groupId>  
                <artifactId>jackson-core-asl</artifactId>  
                <version>1.9.12</version>  
            </dependency>  
    
            <dependency>  
                <groupId>org.codehaus.jackson</groupId>  
                <artifactId>jackson-mapper-asl</artifactId>  
                <version>1.9.12</version>  
            </dependency>
    I am running WAS 8. Not sure what is the problem. I am able to return simple object in json format but not JSONArray object. Please let me know in case I am doing anything wrong.

    I know there are so many existing threads having same discussion. But I didn't find anyone with JSONArray object example.
Working...
X