Mar 11th, 2011, 06:46 PM
Calendar format in ItemWriter
I'm using a FlatFileItemWriter to write data to a CSV file. Is there any way to register a CustomEditorConfigurer with something in the writer configuration (the LineAggregator or FieldExtractor?) so that I have control over the output format of Calendar/Date properties of the objects being written?
I'm looking for the ItemWriter analog to the way you register PropertyEditors with a FieldSetMapper during a read.
Mar 11th, 2011, 08:13 PM
To my knowledge there is not a way to register custom formatters for a given property while using the FlatFileItemWriter and the LineAggregators provided by the framework. This leaves you two options:
- Implement your own FieldExtractor - This would allow you to format the extracted fields in to the desired String for output by the DelimitedLineAggregator.
- Use the FormatterLineAggregator - Since the FormatterLineAggregator uses String.format to generate an output line you can use it to generate your CSV with whatever formatting you'd want. Using this option you would use the format string to determine what each value between the commas would be.
IMHO, I'd go with the FormatterLineAggregator so I didn't have to write any more code.
Tags for this Thread