Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.0.2
-
Component/s: Converters
-
Labels:None
Description
The current date converter (com.thoughtworks.xstream.converters.basic.DateConverter) cannot parse the standard java.sql.Date format (yyyy-MM-dd), nor is there a way to "unregister" the existing the formatter and include my own.
For example, the following XML cannot be parsed into an object:
<Person>
<Name>John Doe</Name> <---- String
<DateOfBirth>1970-02-13</DateOfBirth> <---- java.util.Date
</Person>
To solve the formatting issue, the fix is trivial (simply add the new format to the list of formats, on line 19).
However, it would be useful to be able to "unregister" the default converters, so that users could add back customized versions of the basic converters, if necessary (such as this date-formatting case).
I have verified that the following code correctly solves the issue:
In com/thoughtworks/xstream/converters/basic/DateConverter.java, at line 16, use the following format list:
private ThreadSafeSimpleDateFormat[] formats =
{ new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss.S a", 4, 20), new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ssa", 2, 20), new ThreadSafeSimpleDateFormat("yyyy-MM-dd", 2, 20) };