Support populating nested properties
A fast, programmer-friendly, free CSV library for Java
Brought to you by:
jamesbassett,
kbg
Logged In: YES
user_id=118125
Originator: NO
Hi Wolle78.
Have you been hacking around with my code?? ;-) I guess it is not something that can be accomplished by implementing a processor. Can you send some code you like to see as part of the supercsv distribution, or supply more concrete code examples on how you'd like to see the configuration of these inner beans? I ask for your input as my concerns are, that such configuration can easily become very complex.
cheers,
kasper
Logged In: YES
user_id=1981938
Originator: YES
Thanks for the quick response, Kasper.
I'll try to be a bit more specific. Say I've got the following bean 'DummyRequest' I need to populate from a CSV file:
public class DummyRequest {
...
}
with a nested bean 'DummyUser':
public class DummyUser {
...
}
Now, from my understanding what SuperCSV is able to do is to populate the simple non-Javabean properties
like 'requestNumber, requestDate' using the following line in CSVBeanReader:
...
cache.getSetMethod(resultBean, nameMapping[i]).invoke(resultBean, lineResult.get(i));
...
But I'd like to be able to set properties for class DummyUser too. To map the user name e.g.
a column mapping such as 'user.name' could be used. In my test class I replaced the above line
(along with some additional code) to set this nested property using 'Commons BeanUtils':
...
PropertyUtils.setNestedProperty(resultBean, nameMapping[i], lineResult.get(i));
...
This works for the first simple tests I carried out. However you have to make sure that
the nested bean 'user' is initialized properly to avoid NPEs.
The reason for all this is I'm trying to add CSV batch support to an application and
I want to reuse the existing object model.
Logged In: YES
user_id=118125
Originator: NO
Hi Wolle
Thanks for the extra code. I have been thinking about it, and it may be something that I'll have a look after the next release. Using beanutils is a nice easy way to get started with a proof of concept, but we have to make sure that the beanUtils are caching the methods lookups etc... could I ask you to generate a huge csv file (just one line and repeat it say 100.000 times). To see the speed impact. If there are hardly none, maybe I should abandon my caching strategy and just use the beanUtils instead all together ;-)
many thanks
Kasper
Logged In: YES
user_id=1804740
Originator: NO
Hi, I'm searching for nested property support in your CsvBeanReader's.
So if You have more information please let me know.
Nested property support (a.b.c) and index-based mapping (a.b[1].c) will be included in the upcoming release. There will be a new Reader and Writer that uses Dozer for mapping.