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