Win a copy of Machine Learning with R: Expert techniques for predictive modeling 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Convert ArrayList of custom objects to JSON

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an ArrayList of custom Objects. Each of these objects have an arraylist of another custom object. Then these second level of custom objects have an arraylist of another custom object.

This is how the class hierarchy looks like







I have an arraylist of Undle objects



I would like to convert Undle ArrayList to a JSON. How can I flatten this hierarcical structure of beans and put it in a JSON?

I tried doing something like



and



But it seems that they work only if a String ArrayList is passed.
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What JSON library are you using?

Are you converting just the list or is the list inside a class?



I found the Jackson library fro JSON conversion pretty simple to use. Yet converting a list to JSON in itself is a bit tricky.
 
Thomas Greene
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to covert list inside the list. I am using json-simple but now also considering gson library

 
K. Tsang
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well not that familiar with either one but for Jackson, it utilizes the JavaType to help it determine what the T is for the List<T>

 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!