Menu

#4 Unparsable date exception

open-wont-fix
nobody
None
5
2010-12-20
2009-05-14
Anonymous
No

We are trying to serialize/ deserialize java.util.Date() objects on different system with different java language locales. This result in the following error:

java.text.ParseException: Unparseable date: "2009-05-14 12:03:32.309 CEST"
at java.text.DateFormat.parse(DateFormat.java:337)
at org.simpleframework.xml.transform.DateType$DateFormat.getDate(DateType.java:191)
at org.simpleframework.xml.transform.DateType.getDate(DateType.java:114)
at org.simpleframework.xml.transform.DateTransform.read(DateTransform.java:77)
at org.simpleframework.xml.transform.DateTransform.read(DateTransform.java:46)
at org.simpleframework.xml.transform.Transformer.read(Transformer.java:106)
at org.simpleframework.xml.core.Support.read(Support.java:176)
at org.simpleframework.xml.core.PrimitiveFactory.getInstance(PrimitiveFactory.java:110)
at org.simpleframework.xml.core.Primitive.readTemplate(Primitive.java:220)
at org.simpleframework.xml.core.Primitive.read(Primitive.java:161)
at org.simpleframework.xml.core.Primitive.read(Primitive.java:121)
at org.simpleframework.xml.core.Composite.readObject(Composite.java:477)
at org.simpleframework.xml.core.Composite.read(Composite.java:434)
at org.simpleframework.xml.core.Composite.readAttribute(Composite.java:381)
at org.simpleframework.xml.core.Composite.readAttributes(Composite.java:300)
at org.simpleframework.xml.core.Composite.read(Composite.java:215)
at org.simpleframework.xml.core.Composite.read(Composite.java:161)
at org.simpleframework.xml.core.Composite.read(Composite.java:137)
at org.simpleframework.xml.core.Traverser.read(Traverser.java:78)

The problem seams to be the date format pattern in "org.simpleframework.xml.transform.DateType" -> FULL("yyyy-MM-dd HH:mm:ss.S z")

Bc. the "z" is serialized as locale dependent text expression for e.g. "CEST" or "MESZ" this format cannot be used reliable between systems with different locales.

Two possible solutions:

- change the format pattern to 'yyyy-MM-dd HH:mm:ss.S Z' and use the RFC 822 time zone
or
- initialize the simple date format with a configurable or fix locale to be independent from the default locale

Discussion

  • EECOLOR

    EECOLOR - 2010-04-26

    A workaround would be to use a custom Matcher with a custom implementation of Transform<Date>.

     
  • Niall Gallagher

    Niall Gallagher - 2010-12-20
    • status: open --> open-wont-fix
     
  • Niall Gallagher

    Niall Gallagher - 2010-12-20

    This can be handled by a Transform implementation.

     

Log in to post a comment.