1. XStream
  2. XSTR-424

DateConverter unmarshalls to wrong date using acceptable dateformats


    • 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:
    • 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.

      1. NonLenientDateConverter.java
        2 kB
        Steven Barendregt
      2. NonLenientThreadSafeSimpleDateFormat.java
        2 kB
        Steven Barendregt


        • Assignee:
          Jörg Schaible
          Steven Barendregt
        • Votes:
          0 Vote for this issue
          0 Start watching this issue


          • Created: