0

Is there a way Smooks could generate a CSV file based on a java instance?

I am looking for something like:

public static void main(String[] args){
  Employee emp = new Employee();
  emp.setName("abc");
  emp.setSalary(12312);
  /* set other emp fields */

  smooks.filterSource(.....);
}

CSV Output: "abc","12312", .............

Thanks!

1 Answers1

1

Just take a look at Smooks documentation here, it is done by wrapping your bean with JavaSource object - example can be found here

Then you can use FreeMarker template to transform Java Object into desired format - look here

update Working example can be found here at github

Maciej Dobrowolski
  • 11,561
  • 5
  • 45
  • 67
  • Thanks for the quick reply! The example is about java to xml. And I also checked their documentation but I cannot find anything about writing .csv files.. or maybe I missed something. – user1919204 May 13 '14 at 12:18
  • @user1919204 it is done by custom freemarker template - see updated answer – Maciej Dobrowolski May 13 '14 at 12:34
  • I have checked and it seems this is the way. Thanks for help! If you have a good example (better than the one from Smooks doc), please share. – user1919204 May 13 '14 at 12:55