
|
If you were logged in you would be able to see more operations.
|
|
|
XStream
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
|
|
| JDK version and platform: |
Sun 1.5.0_06 for Windows
|
|
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.
|
|
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.
|
Show » |
|
You may give the latest SNAPSHOT a try.