1. Is it possible to transform csv files without a defined number of fields - as in an item with an undefined number of subitems?
It only supports a fixed number of fields at the moment, but it would be easy to make it work both ways.
2. Is it possible to transform directly from csv to POJO (without transforming to an intermediate XML structure)?
Well it depends on what you mean by "XML Structure". v4.2.1 of the ESB uses Smooks v0.9, which only supports a DOM based processing model, which means it needs to build a DOM of the whole message (in memory) before it can process the message (e.g. inti POJOs). So it does need to create a DOM structure in memory, but doesn't need to create serialized XML structure and pass over it again (re-parse etc). I think one of the examples may do this, but that's just for illustration purposes.
Smooks v1.0 also supports a SAX based processing model, which means it can bypass construction of a DOM and go straight from CSV/EDI/whatever ---> SAX Event Stream ---> POJO i.e. no intermediate structures of any kind.
3. How do i transform my POJO back to csv?
Easiest way is to use a template, which can generate whatever format you like. My preference is for a FreeMarker template (XSLT is a pain IMO). See the model-driven-basic tutorial.
Thanks for the quick reply.
I'm still a bit unsure about 2 though:
My initial approach was to create 2 actions, one for the csv to xml conversion and one for the xml to pojo. As i read your answer it is unnecessary to do this in two steps. If you could point me to the example showing how this is done in one step (mentioned in your reply) it would be much appreciated!
I don't think we have an example of exactly that (i.e. CSV to Java), but there are a number of equivalent examples at http://milyn.codehaus.org/Tutorials:
- "xml-to-java": Uses the default SAX Parser (XML).
- "edi-to-java": Explicitly configures in the SAX Parser for EDI (see 1st resource config in smooks-config.xml).
The exact same principal applies for processing a CSV message, accept for CSV you need to configure the CSV SAX Parser (CSVParser).
See the Stream Parsers section of the Smooks User Guide.
I should add... easiest way of doing this is to first configure in the CSV Parser. Then just run the transform. It will produce a serialized form of the SAX event stream produced by the CSV parser. From this, you can can work out what bean configurations you need to add.
Sounds promising... I think I need to do some tutorial reading though.
Thanks a lot!
I think I need to do some tutorial reading though.
Download and run them...