Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC and JSON array

 
Kishore Tulsiani
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic