Menu

#6 Dedicated builder

csvBeans_0.7
open
csvbeans
5
2005-11-21
2005-11-21
csvbeans
No

Suggested by Rainer Danereder on my blog.

i have the following example for you: Persons might
have more email-adresses (1:n)
public class Person{
// Fields
private String name;
private String adress;
private List listofEmailBeans = new ArrayList(); //
will contain Bean objects. Must be initialized
}
public class Bean {
private String email;
private String provider;
}

Person1{
name=Rainer
adress=austria
listofEmailBeans={email1=rainer-AT-xxx-DOT-com,provider1=testprovider;email2=fouad-AT-yahoo-DOT-de,provider2=yahoo}
}

<csvbeans>
<strategy>
<parser class="org.csvbeans.impl.parsers.CSVBuilder" />
</strategy>
<record class="Person" start="[Record]">
<field name="name" maxLen="20" required="true" />
<field name="adress" maxLen="20" />
<bean name="listofEmailBeans" class="Email"
listElement="true" listSize="2">
<field name="email" maxLen="30" />
<field name="provider" maxLen="10" />
</bean>
</record>
</csvbeans>

Is it possible to write this Objet to the csv-File in
the following style:
[Record]
Rainer;austria;rainer-AT-xxx-DOT-com;testprovider
Rainer;austria;fouad-AT-yahoo-DOT-de;yahoo

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.