Using Smooks (1.4
) to read CSVs and transform them into a Person
POJO.
The CSV consists of comma-separated records on each line, and each record has pipe-delimited fields:
Smith|John|45|male|Johnny|JSmith|JSmizzle,
Smith|Jane|43|female|Janey
etc. Thus each line represents a different person to create. First, a POJO:
public class Person
{
private String lastName;
private String firstName;
private int age;
private boolean isMale;
private List<String> aliases;
}
My problem is with the List
of aliases. Here are the vital parts from my XML configuration:
<reader class="org.milyn.csv.CSVReader">
<param name="fields">lastName,fristName,age,gender,aliases</param>
<param name="separator">|</param>
<param name="strict">false</param>
</reader>
<core:filterSettings type="SAX"/>
<jb:bean beanId="person" class="net.me.myproject.app.Person" createOnElement="csv-set/csv-record/">
<jb:value property="lastName" data="csv-set/csv-record/lastName"/>
<jb:value property="firstName" data="csv-set/csv-record/firstName"/>
<jb:value property="isMale" data="csv-set/csv-record/gender"/>
<jb:value property="age" data="csv-set/csv-record/age"/>
<jb:wiring property="aliases" beanRefId="aliases"/>
</jb:bean>
<jb:bean beanId="aliases" class="java.util.ArrayList" createOnElement="???">
<jb:wiring beanRefId="alias"/>
</jb:bean>
<jb:bean beanId="alias" class="java.util.String" createOnElement="???">
???
</jb:bean>
So where I'm choking is in getting the createOnElement
configured correctly for the aliases
ArrayList as well as each alias
String. Thanks in advance to anybody who can nudge me in the right direction!