• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Require a DesignPattern to create a Complex JSON response

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Require a Design that will create a complex JSON response consisting of List of maps and internally list after retrieving data from DB.Currently using simple servlets wherin objects are created for HashMap and List everytime.
Eg: List<String,HashMap<Object1>>
Object1 is again a List of HashMps and Other plain objects.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure about your question entirely, but I doubt its related to webservices ?

For a good library that can convert your java objects to json, you can have a look at flexjson : http://flexjson.sourceforge.net/

As far as the design is concern, I personally would hate to see List<List<HashMap<String,List<String>>>> or similar Instead, you can create meaningful objects to represent your collection.
eg: List<Employee> and employee would hold List<Address> and address would hold some other list and similar data etc...
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the JavaScript forum.

GSON will also convert objects to JSON. And I agree with Salvin; create an object instead of a complex group of collections.
 
sarita tan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fancis,

Yes this is related to REST webservice JSON response, your resolution of creating a List<Employee> and employee object inturn containing a HashMap of value as an Object eg Employee2 , Wherin Employee2 inturn is a List ...and so on .For a complex JSON response like this one would require to create all these objects ( Employee emp = new Emplyee()) always and would result in complex coding if done in java using servlets, hence require a design pattern which would structure it, or a mechanism to ease the coding /creating multiple objects.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarita tan wrote:Hi Fancis,

Yes this is related to REST webservice JSON response, your resolution of creating a List<Employee> and employee object inturn containing a HashMap of value as an Object eg Employee2 , Wherin Employee2 inturn is a List ...and so on .For a complex JSON response like this one would require to create all these objects ( Employee emp = new Emplyee()) always and would result in complex coding if done in java using servlets, hence require a design pattern which would structure it, or a mechanism to ease the coding /creating multiple objects.



Can you clearly explain your case ? I am not able to clearly understand what you are trying to say here.
I think your requirement is simply a class structure that you are trying to explain using collections. My Opinion is to use actual classes that hold those collections.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic