Geoff Groos
2015-04-11 08:34:17 UTC
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
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