Re: [xstream-user] Joda LocalDate and XStream

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

Re: [xstream-user] Joda LocalDate and XStream

jamcdonald
Thanks for looking into this. I'm using joda-time 1.5.2 and xstream 1.3.

I ran your code. Looks like it is a problem with joda-time:

--2008-07-11 10:43:25,375 JodaTimeUtilsTest.testSerializeLocalDate(253)--

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>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 (2008-07-03)


--
John Alan McDonald
[hidden email]
 
-------------- Original message from Jörg Schaible <[hidden email]>: --------------


> Hi John,
>
> ________________________________
>
> From: [hidden email]
> Sent: Thursday, July 10, 2008 11:01 PM
> Subject: [xstream-user] Joda LocalDate and XStream
>
> 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
>
>
> 1215043200000
>
> resolves-to="org.joda.time.chrono.ISOChronology$Stub"
> serialization="custom">
>
>
> id="3" resolves-to="org.joda.time.DateTimeZone$Stub"/>
>

>

>

>
> 2008-07-02
>
>
> 1215043200000
>
> resolves-to="org.joda.time.chrono.ISOChronology$Stub"
> serialization="custom">
>
>
> resolves-to="org.joda.time.DateTimeZone$Stub"
> serialization="custom">
>
> America/Los_Angeles
>

>

>

>

>

>
> 2008-07-02
> ________________________________
>
> Works for me (TM). What version of joda-time you're using? However, problem
> might be ralted with your TZ having a negative offset. Can you run a short test
> with this:
>
> =========== %< ============
> 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
>
> 1215043200000
>
> resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
>
>
> resolves-to="org.joda.time.DateTimeZone$Stub"/>
>

>

>

> 2008-07-03 (2008-07-03)
>
> 1215043200000
>
> resolves-to="org.joda.time.chrono.ISOChronology$Stub" serialization="custom">
>
>
> resolves-to="org.joda.time.DateTimeZone$Stub" serialization="custom">
>
> Europe/Berlin
>

>

>

>

>

> 2008-07-03 (2008-07-03)
>
> I am curious about the dates in prackets using pure Java serialization ...
>
> - Jörg
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_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...