Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Spring MVC and JSON array

 
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??
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic