Java8 LocalDate not supported by XStream 1.4.6 ?

1,527 views
Skip to first unread message

Jean-Francois James

unread,
Dec 3, 2014, 7:57:36 AM12/3/14
to axonfr...@googlegroups.com
Hi all,

I've developped an Event with LocalDate attribute. When testing it, I get the following exception:
com.thoughtworks.xstream.converters.ConversionException: Cannot convert type java.time.Ser to type java.time.LocalDate
---- Debugging information ----
class               : org.axonlab.basics.jsr303.api.PersonCreatedEvent
required-type       : org.axonlab.basics.jsr303.api.PersonCreatedEvent
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /org.axonlab.basics.jsr303.api.PersonCreatedEvent/dateBirth
line number         : 1
version             : 1.4.6


It seems that XStream is not able to convert Java8 LocalDate. I've not found any related additional converters and it doesn't seem to included in XStream 1.4.7.
Do I miss ST? Did anyone already encountered the same issue ?

Phil Whiles

unread,
Dec 3, 2014, 9:40:10 AM12/3/14
to axonfr...@googlegroups.com
I too faced this in the last few weeks, and I have a solution for you!

You will need a LocalDateConverter :

public class LocalDateConverter extends AbstractSingleValueConverter {

public boolean canConvert(Class type) {
return (type!=null) && LocalDate.class.getPackage().equals(type.getPackage());
}

public String toString (Object source) {
return source.toString();
}

public Object fromString(String str) {
try {
return LocalDate.parse(str);
} catch (Exception e) {
// deal with it
}
}

}

When you wire up the EventStore (I do it in code) :

LocalDateConverter conv = new LocalDateConverter();
Xtream xstream = new XStream();
xstream.registerConverter(conv);
XStreamSerializer xstreamSerial = new XStreamSerializer (xstream);

EventStore store = new JpaEventStore (entityManagerProvider(), xstreamSerial);



Forgive typos please - I cannot paste work code externally, so retyped above.
I use obviously use JPA - so YMMV.

HTH!

Phil



Jean-Francois James

unread,
Dec 3, 2014, 9:49:43 AM12/3/14
to axonfr...@googlegroups.com
You're a boss thanks. I will test it!

Kevin Condon

unread,
Jun 13, 2016, 11:57:54 AM6/13/16
to Axon Framework Users
This helped me get Java Instant support working with very similar converter code. It really helped to have the event store wiring example. Thanks. :)

Kevin
Reply all
Reply to author
Forward
0 new messages