0

I have a spring boot application where need to send back application/csv response for list of object having nested beans needs to be converted to CSV using openCsv or any other tool. e.g. Java classes:

class MyData {
    Lis<Person> persons;
}

class Person {
    String id;
    String lname;
    String fname;
    Date dob;
    Address address;
}

class Address {
    String line1;
    String line2;
    String pinCode;
}

CSV data:

id      lname   fname   line1           line2
1       Doe     John    123 Main St     Anytown, USA
2       Dean    James   111 Some St     Othertown, USA
3       Burger  Sam     99 Beach Avenue Sometown, USA

Note that, few fields like Prson.dob & Person.Address.pinCode are excluded from the conversion. Sample code will help a lot.

Saurabhcdt
  • 1,010
  • 1
  • 12
  • 24
  • 3
    What have you tried? What is your problem exactly? – pandaadb Jan 20 '20 at 13:12
  • Same question: https://stackoverflow.com/questions/60933155/opencsv-convert-object-with-nested-bean-to-csv. Did you find any answer for the same? – SatyaKinkar Gorai Mar 31 '20 at 08:01
  • @SatyaKinkarGorai I could not find any automated way for this. So, right now, i'm iterating over the java list & converting them in csv row. Please let me know if you find any automated way. thanks. – Saurabhcdt Apr 01 '20 at 09:37

0 Answers0