Announcement Announcement Module
No announcement yet.
Date Property editor problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.

    <bean id="myFieldSetMapper"
    		<property name="targetType" value="domain.MyClass" />
    		<property name="customEditors">
    				<entry key="org.springframework.batch.item.file.transform.Range[]">
    						class="org.springframework.batch.item.file.transform.RangeArrayPropertyEditor" />
    				<entry key="java.util.Date">
    					<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
    							<bean class="java.text.SimpleDateFormat">
    								<constructor-arg value="ddMMyy" />
    						<constructor-arg value="false" />
    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.


  • #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.


    • #3
      Thanks Marten. It is working.