Hi,

I would like to know How we can extend the existing method
marshall/unmarshall of the class CsvDataFormat (supercsv component) in such
a way that we can provide the CsvPreferences (STANDARD, EXCEL, ...) and the
bean to be used to map the data ?

idea : 

from("file://myCSVfile")
.marshal().csv("CsvPrefs","UserBeanToBeUsedForMappingData")
.to("");

Why such request ? Because the SuperCSV classes allow to map directly the
content of a CSV file (with or withour headers) to a POJO and we can define
i nthe preference the kind of CSV provided (excel, ...) (see doc for more
info : http://supercsv.sourceforge.net/codeExamples_general.html) ?

ex :

public class UserBean {
    String username, password, street, town;
    int zip;

    public String getPassword() { return password; }
    public String getStreet() { return street; }
    public String getTown() { return town; }
    public String getUsername() { return username; }
    public int getZip() { return zip; }
    public void setPassword(String password) { this.password = password; }
    public void setStreet(String street) { this.street = street; }
    public void setTown(String town) { this.town = town; }
    public void setUsername(String username) { this.username = username; }
    public void setZip(int zip) { this.zip = zip; }
}

class ReadingObjects {
  public static void main(String[] args) throws Exception{
    ICsvBeanReader inFile = new CsvBeanReader(new FileReader("foo.csv"),
CsvPreference.EXCEL_PREFERENCE);
    try {
      final String[] header = inFile.getCSVHeader(true);
      UserBean user;
      while( (user = inFile.read(UserBean.class, header, processors)) !=
null) {
        System.out.println(user.getZip());
      }
    } finally {
      inFile.close();
    }
  }
}

KR,




-----
Charles Moulliard
SOA Architect

My Blog :  http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/  
-- 
View this message in context: 
http://www.nabble.com/Is-there-a-way-to-extend-marshall-method-of-CsvDataFormat-class-tp20955830s22882p20955830.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to