History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-424
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Joerg Schaible
Reporter: Steven Barendregt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

DateConverter unmarshalls to wrong date using acceptable dateformats

Created: 03/Sep/07 08:16 AM   Updated: 25/Feb/08 05:01 PM
Component/s: Converters
Affects Version/s: 1.2, 1.2.2
Fix Version/s: 1.3

File Attachments: 1. Java Source File NonLenientDateConverter.java (2 kb)
2. Java Source File NonLenientThreadSafeSimpleDateFormat.java (2 kb)


JDK version and platform: Sun 1.5.0_06 for Windows


 Description  « Hide
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.





 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 15/Sep/07 09:18 AM
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.

Joerg Schaible - 25/Feb/08 05:01 PM
Closing issues before next release.