Unwarranted Date Drift During JAXB Serialize Deserialize
843834Oct 30 2008 — edited Feb 24 2009My experience with the issue is with JAXB installed from JAXB2_20071219.jar
It may be fixed in a different version of JAXB.
If a data element has been designated in the schema as a date (extends
xs:date) and is represented in code as type Calendar, and if the
serialization happens in a different timezone context than the
de-serialization, it is possible for the serialization/de-serialization
to change the day. This is a significant problem when the day in
question is actually a "nominal day" and not a point-in-time. A good
example is a birthdate used in a legal context. In the legal context,
what is usually wanted is not a point-in-time, but, the day as it
existed in the location where a person was born, and as it currently
exists on a birth certificate. Here is how this unwarranted change of a
date happens:
javax.xml.bind.DatatypeConverter.printDate serializes the date as follows:April 10, 2008 in Alaska Daylight Time
becomes <report_date>2008-04-10-08:00</report_date>
and then if it is de-serialized in the context of PDT (perhaps by a computer in a different timezone processing a SOAP response)
April 10, 2008 in Alaska Daylight Time,
de-serialized in PDT (UTC -9:00)
becomes April 9, 2008 (23:00)
Perhaps in the code below timezone information could be optional? That is, provide a serialization option that will render a date with no timezone info? The workaround we have adopted is to serialize into a string and then do search and replace on the string, removing the timezone info and leaving the data. This has worked in our experience. See [https://elandings.alaska.gov/confluence/x/tYBp]
com.sun.xml.bind.DatatypeConverterImpl
public String printDate(Calendar val) {
return CalendarFormatter.doFormat((new StringBuilder("%Y-%M-%D").append("%z")).toString(),val);
}