Take a look at the fixedLength sample: https://src.springframework.org/svn/...ixedLength.xml
It uses the FormatterLineAggregator to aggregate a CustomerCredit object. The aggregator is defined as follows:
Code:
<bean class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
<property name="fieldExtractor">
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<property name="names" value="name,credit" />
</bean>
</property>
<property name="format" value="%-9s%-2.0f" />
</bean>
The format, "%-9s%-2.0f", will apply to an array containing two items. See http://java.sun.com/j2se/1.5.0/docs/...Formatter.html for more information on Java's Formatter.
The BeanWrapperFieldExtractor is pretty convenient if the object you are aggregating has getters for the properties you need to write, but you can write your own custom FieldExtractor too:
Code:
public class CustomerCreditFieldExtractor implements FieldExtractor<CustomerCredit> {
public Object[] extract(CustomerCredit item) {
return new Object[]{item.getName(), item.getCredit()};
}
}
As mentioned before, the PassThroughFieldExtractor is useful when then object being aggregated is already an array or a Collection.