• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Error 406: Spring MVC not able to return JSONArray object.

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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:



I have tried both these entries in spring-context.xml



and




My pom.xml has these dependencies:



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.
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, check the value of the Accept http header tag that the client (ajax) send to the server.

Use TCP/IP mon to see the http request sent to the server.
 
pawan chopra
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply . Value in the header is applicarion/json.
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the server side,
Have you look at the Producible Media Types. See documentation.
produces attribute of @RequestMapping.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I use just

<mvc:annotation-driven/>



Then in my Controller i just return my domain object or List of my domain object with @ResponseBody and it works. No need to add anything else.

In your code, I notice you aren't returning a domain object, but a JSON specific type object. Maybe Jackson doesn't know how to convert that.

What Exception do you get? Can you post the stack trace here?

What does your jquery code look like to make the call?

Ah you say simple objects work. Maybe there is a circular dependency in the JSONArray object. You might need to add some @JsonIgnore annotations in that class. But if you don;t have that code, then you might have to make an xml jackson config for that class.

Mark
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
+1 to what Mark said. I just wanted to add that jackson 2 support is now in Spring 3.2 and this adds much needed love for handling circular dependencies.
 
pie. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic