XStream

serialize/deserialize subtracts 1 day from Joda-Time LocalDate instances.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.3
  • Fix Version/s: 1.3.1
  • Component/s: None
  • Labels:
    None
  • JDK version and platform:
    Sun JDK 1.6

Description

=========== %< ============
final LocalDate ld0 = new LocalDate(2008, 07, 03);
final XStream xs = new XStream();
final String xml0 = xs.toXML(ld0);
final LocalDate ld1 = (LocalDate) xs.fromXML(xml0);
final String xml1 = xs.toXML(ld1);
final LocalDate ld2 = (LocalDate) xs.fromXML(xml1);

LocalDate ld1s = null;
LocalDate ld2s = null;
try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ld0); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ld1s = (LocalDate)ois.readObject(); ois.close(); baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(ld1s); oos.close(); ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ld2s = (LocalDate)ois.readObject(); ois.close(); } catch (Exception e) { // nothing }
System.out.println(ld0.toString() + '\n' + xml0 + '\n'
+ ld1 + " (" + ld1s + ")\n" + xml1 + '\n'
+ ld2 + " (" + ld2s + ")\n");
=========== %< ============

For me it prints:

2008-07-03
<org.joda.time.LocalDate>
<iLocalMillis>1215043200000</iLocalMillis>
<iChronology class="org.joda.time.chrono.ISOChronology"
resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
<org.joda.time.chrono.ISOChronology_-Stub>
<org.joda.time.tz.FixedDateTimeZone
resolves-to="org.joda.time.DateTimeZone$Stub"/>
</org.joda.time.chrono.ISOChronology_-Stub>
</iChronology>
</org.joda.time.LocalDate>
2008-07-02 (2008-07-03)
<org.joda.time.LocalDate>
<iLocalMillis>1215043200000</iLocalMillis>
<iChronology class="org.joda.time.chrono.ISOChronology"
resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
<org.joda.time.chrono.ISOChronology_-Stub>
<org.joda.time.tz.CachedDateTimeZone
resolves-to="org.joda.time.DateTimeZone$Stub" serialization="custom">
<org.joda.time.DateTimeZone_-Stub>
<string>Europe/Berlin</string>
</org.joda.time.DateTimeZone_-Stub>
</org.joda.time.tz.CachedDateTimeZone>
</org.joda.time.chrono.ISOChronology_-Stub>
</iChronology>
</org.joda.time.LocalDate>
2008-07-02 (2008-07-03)

Activity

Hide
Robert Hanson added a comment -

this is still an issue in version 1.5

Show
Robert Hanson added a comment - this is still an issue in version 1.5
Hide
Robert Hanson added a comment -

FYI - this seems to be an XStream issue in the way it serializes the object/

http://www.nabble.com/Joda-LocalDate-and-XStream-td18391808.html
.

Show
Robert Hanson added a comment - FYI - this seems to be an XStream issue in the way it serializes the object/ http://www.nabble.com/Joda-LocalDate-and-XStream-td18391808.html .
Hide
Robert Hanson added a comment -

> this is still an issue in version 1.5

Errr... ignore. I meant 1.3.

Show
Robert Hanson added a comment - > this is still an issue in version 1.5 Errr... ignore. I meant 1.3.
Hide
Joerg Schaible added a comment -

Hi John, this problem has in fact revealed a long standing bug for nested serializable objects that have both writeReplace/readResolve methods. Fixed in head now.

Show
Joerg Schaible added a comment - Hi John, this problem has in fact revealed a long standing bug for nested serializable objects that have both writeReplace/readResolve methods. Fixed in head now.
Hide
Joerg Schaible added a comment -

Set correct fix version.

Show
Joerg Schaible added a comment - Set correct fix version.
Hide
Joerg Schaible added a comment -

Fixed for upcoming release.

Show
Joerg Schaible added a comment - Fixed for upcoming release.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: