XStream

DateConverter unmarshalls to wrong date using acceptable dateformats

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.2, 1.2.2
  • Fix Version/s: 1.3
  • Component/s: Converters
  • Labels:
    None
  • JDK version and platform:
    Sun 1.5.0_06 for Windows

Description

I'm using a DateConverter with the following configuration :

String[] dateFormats = new String[] { "yyyyMMdd", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd" };
xstream.registerConverter(new DateConverter("yyyy-MM-dd'T'HH:mm:ss.S'Z'", dateFormats));

When I try to unmarshal the following date : 2001-12-17T09:30:47Z (xsd:datetime)
the resulting date is Thu Nov 02 00:00:00 CET 2000
I debugged and saw that the first acceptable format yyyyMMdd is used for this date.

When I change the order of the first two acceptable formats so that the exact format for my test date is used, everything works fine.

I think the problem lies in the default lenient character of the SimpleDateFormat, that is used internally by the DateConverter.
To do some tests I created two quick and dirty classes : a subclass of DateConverter and a subclass of ThreadSafeSimpleDateFormat in which the instances of SimpleDateFormat are made non-lenient.
Now everything works fine. The exact matching date format is selected and unmarshalled correctly, independent of the order of the acceptable formats.

I tried versions 1.2 and 1.2.2 , both behave in this way.

Activity

Hide
Joerg Schaible added a comment -

The DateConverter will operate in future by default in non-lenient mode. Lenient mode can be chosen by instantiating an own DateConverter with an additional flag as parameter.

You may give the latest SNAPSHOT a try.

Show
Joerg Schaible added a comment - The DateConverter will operate in future by default in non-lenient mode. Lenient mode can be chosen by instantiating an own DateConverter with an additional flag as parameter. You may give the latest SNAPSHOT a try.
Hide
Joerg Schaible added a comment -

Closing issues before next release.

Show
Joerg Schaible added a comment - Closing issues before next release.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: