3

Could it possible that JDK 5 can produce

"default message [Failed to convert property value of type 
'java.lang.String' to required type 'java.util.Date' for property 
'orderDate'; nested exception is  org.springframework.core.convert.ConversionFailedException:Failed to convert
from type java.lang.String to type java.util.Date for value 'Mon May 27 12:27:20 ART 2013'"

But not on JDK6? current application is Spring on JBoss so that the conversion is not explicit. I get this issue from Jboss server on one machine but not from other Jboss on another machine. However right now somehow I can not check the JVM detail with the server has the issue.

Dreamer
  • 7,333
  • 24
  • 99
  • 179
  • 1
    Maybe `ART` is a new TimeZone that one machine is not aware of? – jahroy May 28 '13 at 22:58
  • 1
    Maybe it's not new, but it sounds like TimeZone strings can be very machine dependent... Here's [a question](http://stackoverflow.com/q/1707799/778118) that has some discussion. – jahroy May 28 '13 at 23:03
  • 2
    Here's another one, that says that the `Date` class has significant changes from JDK5 to JDK6: http://stackoverflow.com/questions/10481122/java-util-date-returning-different-dates-in-jdk-5-and-jdk-6 – Konstantin Yovkov May 28 '13 at 23:07
  • Thanks everyone, it seems a platform issue. Current testing server is in US on windows, but remote testing server is in Argentina on Linux...so generally how to get a solution to these complicated situation? – Dreamer May 29 '13 at 01:54

1 Answers1

2

I doubt JDK Date functions has significant change from version 5 to 6. Maybe it's locale differences between two environments.

Also if you're on Spring MVC it's better practice to define a date string format, and register a property editor for it on your controller, so you can always parse/format regardless of locales, eg:

@InitBinder
public void registerDateBinder(WebDataBinder binder) {
  DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • Thanks but what if we want the data format customizable from external properties file, is above solution still doable? – Dreamer May 28 '13 at 23:06
  • 1
    definitely, instead of hardcoding `"dd/MM/yyyy"`, place it an a system property / config file and pull it when registering the date binder – gerrytan May 28 '13 at 23:16
  • I get an exception: java.lang.IllegalArgumentException: Illegal pattern character 'e' after with customize pattern. But there is no such 'e' from custominze pattern(default_date_format=MMM/dd/yyyy), so what's going on there? Thanks again for the help. – Dreamer May 28 '13 at 23:34
  • 1
    I think that exceptions arise when you tried to parse input that doesn't conform to the date format. – gerrytan May 28 '13 at 23:50
  • in current controller we have more than one data format on the UI, so what is the solution to have different binder to each method ? – Dreamer May 29 '13 at 01:55
  • I would normalize all the date data first so they all have uniform format. This might be hard and painful but better to avoid future complexity – gerrytan May 29 '13 at 04:18