Announcement Announcement Module
Collapse
No announcement yet.
BeanWrapperFieldSetMapper not working for Dates Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanWrapperFieldSetMapper not working for Dates

    I am reading a fixed length file. One of the fields in the line is a date.
    So I am using FlatFileItemReader with FixedLengthTokenizer and BeanWrapperFieldSetMapper. I also added property editors. Here is my Spring configuration:

    Code:
    <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    	<property name="customEditors">
    		<map>
    			<entry key="org.springframework.batch.item.file.transform.Range[]">
    				<bean class="org.springframework.batch.item.file.transform.RangeArrayPropertyEditor" />
    			</entry>
    			<entry key="java.util.Date">
    				<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
    					<constructor-arg>
    						<bean class="java.text.SimpleDateFormat">
    							<constructor-arg value="MMddyyyy" />
    						</bean>
    					</constructor-arg>
    					<constructor-arg value="true" />
    				</bean>
    			</entry>
    		</map>
    	</property>
    </bean>
    
    <bean id="myReader" class="org.springframework.batch.item.file.FlatFileItemReader">
    	<property name="resource" value="file:/mydocs/person.txt" />
    	<property name="comments" value="Header, 1.0, END" />
    	<property name="lineMapper">
    		<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
    			<property name="lineTokenizer">
    				<bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
    					<property name="names" value="id,name,dob,comments" />
    					<property name="columns" value="1-4,5-8,9-16,17-" />
    				</bean>
    			</property>
    			<property name="fieldSetMapper">
    				<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
    					<property name="targetType" value="com.Person" />
    				</bean>
    			</property>
    		</bean>
    	</property>
    </bean>
    With above configuration, I am getting following exception:

    org.springframework.batch.item.file.mapping.Bindin gException:Failed to convert property value of type [java.lang.String]
    to required type [java.util.Date] for property 'dob'; nested exception is java.lang.IllegalArgumentException:
    Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'dob':
    no matching editors or conversion strategy found


    Do I need to set customEditors property for BeanWrapperFieldSetMapper? If that is the case how RangeArrayPropertyEditor is working?

    Also I set the 'comments' property for FlatFileItemReader but it does not have any affect. Can someone tell me how it works? TIA.

  • #2
    I moved customEditors property from customEditorConfigurer to BeanWrapperFieldSetMapper and it worked fine.

    I still need to find why comments are not working.

    Comment


    • #3
      Comments are also working. I should set them in a list instead of a String with commas.

      Comment


      • #4
        hi pgondi, i'm having the same problem. did you get it solved? can you please post your final configuration?

        thanks!

        Comment

        Working...
        X