Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Create Json from a List's data  RSS feed

 
Vasilis Souvatzis
Ranch Hand
Posts: 94
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EDIT: Nevermind, I did it. I'll post the code later.

Right, in the beginning I thought it'd be quite easy to do what I want, in practice though I can't figure it out.

Basically, I want to create a Json that contains all of my DB table's data. Something along the lines of:


All these names though are retrieved from the DB and held in Lists. My first reaction was to iterate the Lists, after specifying an ArrayBuilder outside the loop, and add these objects. Problem is it doesn't work. Either I don't add the elements correctly or it doesn't write the output correctly.

How would you write a similar Json iterating a List?
 
Vasilis Souvatzis
Ranch Hand
Posts: 94
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remembered I didn't post the code. So here is the whole method that generates said JSON:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!