Discussion:
[xstream-user] java.time does not appear to serialize/deserialize properly
Geoff Groos
2015-04-11 08:34:17 UTC
Permalink
Hey guys,

I’m wondering what you guys think of XStream + the new (java 1.8) java.time library.

I’ve started replacing joda.time uses with java.time ones (as encouraged by the Joda time guys themselves) and I only noticed when I ran my persistence tests that anything causing XStream to touch a java.time.Instant instance would fail.

A simple test to reproduce:

private static class ClassWithTimestamp{
public final Instant timestamp = Instant.now();
}

@Test
public void when_serializing_a_timestamp_xstream_should_have_no_trouble(){
//setup
XStream vanillaXStream = new XStream();
ClassWithTimestamp originalInstance = new ClassWithTimestamp();

//act
String serialized = vanillaXStream.toXML(originalInstance);
ClassWithTimestamp deserialized = (ClassWithTimestamp) vanillaXStream.fromXML(serialized);

//assert
assertThat(deserialized.timestamp).isEqualTo(originalInstance.timestamp);
}


Thoughts?

I’m implementing custom converters now, and since java.time is so much more interoperable with the ISO 8601 spec than that worse-than-useless java.util.Date stuff, I’m thinking I’ll register these as immutable and have them serialize and deserialize to nice ISO strings.

I’d be honored if I could push that stuff upstream to you guys!

-Geoff

Sent from Windows Mail
Jörg Schaible
2015-04-13 07:11:08 UTC
Permalink
Hi Geoff,
Post by Geoff Groos
Hey guys,
I’m wondering what you guys think of XStream + the new (java 1.8)
java.time library.
Someone has to start :-)
Post by Geoff Groos
I’ve started replacing joda.time uses with java.time ones (as encouraged
by the Joda time guys themselves) and I only noticed when I ran my
persistence tests that anything causing XStream to touch a
java.time.Instant instance would fail.
private static class ClassWithTimestamp{
public final Instant timestamp = Instant.now();
}
@Test
public void
when_serializing_a_timestamp_xstream_should_have_no_trouble(){
//setup
XStream vanillaXStream = new XStream();
ClassWithTimestamp originalInstance = new ClassWithTimestamp();
//act
String serialized = vanillaXStream.toXML(originalInstance);
ClassWithTimestamp deserialized = (ClassWithTimestamp)
vanillaXStream.fromXML(serialized);
//assert
assertThat(deserialized.timestamp).isEqualTo(originalInstance.timestamp);
Post by Geoff Groos
}
Thoughts?
Well, actually XStream should have been able to marshal/unmarshal this, but
I'll have a look.
Post by Geoff Groos
I’m implementing custom converters now, and since java.time is so much
more interoperable with the ISO 8601 spec than that worse-than-useless
java.util.Date stuff, I’m thinking I’ll register these as immutable and
have them serialize and deserialize to nice ISO strings.
That would be definitely the best approach.
Post by Geoff Groos
I’d be honored if I could push that stuff upstream to you guys!
A very welcome addition to XStream, it would be nice to get such a
contribution!

Cheers,
Jörg

Note, XStream is currently in the transition from Codehaus to Github. If
you're ready to contribute, please give a note here that we may point you to
the proper place.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Continue reading on narkive:
Search results for '[xstream-user] java.time does not appear to serialize/deserialize properly' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 2006-10-11 00:02:47 UTC
software
Loading...