Announcement Announcement Module
Collapse
No announcement yet.
Date Property editor problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date Property editor problem

    I am using the CustomDateEditor to convert the date from flat file. The flat file contains the date in ddmmyy format. The record is converted to Bean which is JPA entity.

    Code:
    <bean id="myFieldSetMapper"
    		class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
    		<property name="targetType" value="domain.MyClass" />
    		<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="ddMMyy" />
    							</bean>
    						</constructor-arg>
    						<constructor-arg value="false" />
    					</bean>
    				</entry>
    			</map>
    		</property>
    	</bean>
    I want to catch the Exception if the date is invalid in validation Processor.

    The codes are running fine. But when the invalid date occurs, it converted to some arbitrary date and no exception thrown. for example if the String passed to the date field is 351308 in ddmmyy format, it is converting to '04-feb-2009' instead of throwing the exception.

    Please suggest how to correct the problem. I am using spring 3.1.1 and spring batch 2.1.8.

    Thanks

  • #2
    This isn't a PropertyEditor problem that is default behavior of the SimpleDateFormat... By default it is lenient (i.e. allow illegal dates and convert them into something useable i.e. 31022012 would become 02032012)... Set lenient to false on the SimpleDateFormat and you will get an exception.

    Comment


    • #3
      Thanks Marten. It is working.

      Comment

      Working...
      X