LocalDate and XStream

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

LocalDate and XStream

jamcdonald
Round trip serialize/deserialize with XStream appears to subtract a day from a LocalDate. My workaround for this is to use a custom converter for LocalDate that formats/parses the LocalDate as a String.

My main concern is whether this is exposing a problem in either JodaTime or XStream that could affect other code.

    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);
    System.out.println(ld0 + '\n' + xml0 +
'\n' +
                       ld1 + '\n' + xml1 + '\n' +
                       ld2);

produces (note the second serialize/deserialize round trip preserves the date):

2008-07-03

<org.joda.time.LocalDate id="1">
  <iLocalMillis>1215043200000</iLocalMillis>
  <iChronology class="org.joda.time.chrono.ISOChronology" id="2"    
    resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
    <org.joda.time.chrono.ISOChronology_-Stub>
      <org.joda.time.tz.FixedDateTimeZone
        id="3" resolves-to="org.joda.time.DateTimeZone$Stub"/>
    </org.joda.time.chrono.ISOChronology_-Stub>
  </iChronology>
</org.joda.time.LocalDate>

2008-07-02

<org.joda.time.LocalDate id="1">
  <iLocalMillis>1215043200000</iLocalMillis>
  <iChronology class="org.joda.time.chrono.ISOChronology" id="2" 
    resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
    <org.joda.time.chrono.ISOChronology_-Stub>
      <org.joda.time.tz.CachedDateTimeZone id="3"
        resolves-to="org.joda.time.DateTimeZone$Stub" serialization="custom">
        <org.joda.time.DateTimeZone_-Stub>
          <string>America/Los_Angeles</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


 
--
John Alan McDonald
[hidden email]

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...