• 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

Populate Complex Java Objects reading CSV Header.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I want to read an csv file and generate an xml.
The approach i am following is to read csv headers which would be first line in csv file, and they will represent the POJO's.
Then i am passing the POJO to some xml generation code.
The problem i am facing is when the headers which are present on first line of csv would be for complex objects.
For e.g.
Employee is the class having empId(int),firstName(String),lastName(String) and address(Address).
Address would be another class which would have addressline1(String),addressline2(String) so on..

Please let me know how should I represent the headers in csv, read the csv's and populate the java object?

Looking forward for a quick reply.

Thanks in advance
Cheers.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find something useful in the ServingXML toolkit - it has examples various ways to handle flat files such as CSV.

Bill
 
sam kulkarni
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for a quick reply.
But I was unable to find any code written in java on the site you provided.
Sorry if i have missed out on that.
Kindly let me know if there is some site where i can find the same.
or some other approach.

Thanks.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The https://coderanch.com/how-to/java/AccessingFileFormats page lists several libraries you can use for reading CSV; some of them will create Java objects of the data.
 
Not so fast naughty spawn! I want you to know about
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic