printfspring-batchspring-batch-adminspring-batch-job-monitoringspring-batch-excel

Spring Batch configuration Formatter Conversion change


I have an Item Writer as below:

<beans:property name="lineAggregator">
  <beans:bean class="org.spring...FormatterLineAggregator">
    <beans:property name="fieldExtractor">
        <beans:bean class="org.springframework..BeanWrapperFieldExtractor">
             <beans:property name="names" value="column1" /> 
            </beans:bean>
            </beans:property>
        <beans:property name="format" value="%05d" /> 
    </beans:bean>

when I tired with format value ="%05d" I getting my expected value as 00012. but when I tried by changing formatter value with value ="%05s" I am getting getting whitespaces like this " 12" which need to be replaced with zero.

suppose if I have value as AI2 means then my formatted value has to be 000AI2. That's y I am trying to change conversion from d to s.

How to do that :?


Solution

  • %d is used to format numbers only. Usually in fixed lenght file we pad string data with spaces and numbers with "0".

    If you have no choise and the data you want to pad with "0" is a String, maybe you can do the conversion logic in the processor of your step ?