Meaningless Drivel is fun!*
The moose likes Spring and the fly likes Spring MVC and JSON array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC and JSON array" Watch "Spring MVC and JSON array" New topic
Author

Spring MVC and JSON array

Kishore Tulsiani
Greenhorn

Joined: Jan 15, 2010
Posts: 21
I am implementing Ajax on my pages and using Jquery for Ajax calls and using JSON to send the data to controller.

Can any one tell me how to map the JSON array in spirng controller command object ?

for example if following data is there

var jsondata = {
"birthday" : "26/01/1983",
"placeofbirth" : "mubai" ,
"names" : [ "mubai", "delhi" , "ahmedabad"]

};

what should be there for names on controller command bean??
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Kishore Tulsiani wrote:I am implementing Ajax on my pages and using Jquery for Ajax calls and using JSON to send the data to controller.

Can any one tell me how to map the JSON array in spirng controller command object ?

for example if following data is there

var jsondata = {
"birthday" : "26/01/1983",
"placeofbirth" : "mubai" ,
"names" : [ "mubai", "delhi" , "ahmedabad"]

};

what should be there for names on controller command bean??


Not that this answers your question.

But personally, I wouldn't use the older controller classes anymore. That is so Spring 2.0. ;)

Today in Spring 3.0 with RESTful Web Services so easy to implement, I would configure the ContentNegotiatingViewResolver with JSONView from the Jackson library. (easy to get the library), then have a POJO controller that returns your Java object that holds the data. Then have the JSON automatically generated by the incoming URL request stating that you want it in JSON by adding ".json" to the end of your URL, or changing the accept header of the URL request to ask for json.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring MVC and JSON array
 
Similar Threads
Calling a new JSP form a Spring Controller using Ajax
How to pass Object to Javascript function in JSP
How to read + operator using javascript
Front man example
Kris, on your book