1

I have been working with Super CSV and i have a doubt how it works with dynamic bean, that to for deep mapping and indexed mapping.

Eg code below

Class Car{
    List<Model> carModels = new ArrayList<Model>();// with setters and getters.
}

If my List of car models vary in size then how to handle field mapping and reference XML mapping dynamically without hard coding the index?

Example data

Header/Mapper

name,ip,highAvailability[0].category, highAvailability[0].ip, highAvailability[1].category, highAvailability[1].ip

Values

testNames, 12.18.12.20, Secondary, 12.1.1.1, primary,12.0.10.10 // 1st bean

testNames, 12.18.12.20, Secondary, 12.1.1.1 // 2nd bean

The difference between above bean will that 1st bean has 2 highAvailability objects were the second one has 1 highAvailablity object. Now I do not want to hard code the index since I am unaware of the number of highAvailability objects.

James Bassett
  • 9,458
  • 4
  • 35
  • 68
kavin
  • 174
  • 2
  • 11
  • You're obviously using the Dozer extension, but are you reading or writing? Do you have an example CSV file to demonstrate the problem? – James Bassett May 19 '14 at 09:59
  • I need to do both where there will be columns with dynamic size i.e the list of inner objects will differ. Will give you an example. – kavin May 19 '14 at 11:12
  • You may want to read some related questions [here](http://stackoverflow.com/a/11698684/1068649) and [here](http://stackoverflow.com/a/18243758/1068649). If possible, ensure that your CSV file has the same number of columns on every row. This way you can hopefully look at the header and figure out how to dynamically create the mapping. – James Bassett May 19 '14 at 23:26
  • I have read that post and I am in trouble now. I cant implement those ideas. Need to look for an alternative. Anyhow @HoundDog Thanks for your time. – kavin May 20 '14 at 04:52

0 Answers0