File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 17260
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC and JSON array