Thanks Thierry, Also, FWIW, I asked about this on the xstream list and they suggested a better way to handle this.
http://comments.gmane.org/gmane.comp.java.xstream.user/8055 On Apr 6, 2012, at 10:01 AM, Thierry Boileau wrote: > Hello Bjorn, > > thanks for sharing this experience. We are aware that customizing the Restlet > XStream converter is not an easy thing. This could lead to inherit from the > provided converter helper (org.restlet.ext.xstream.XStreamConverter) and > register it to the Engine > (Engine.getInstance().getRegisteredConverters().add(ConverterHelper))... > I've added a reference of this thread to the issue #291 > (https://github.com/restlet/restlet-framework-java/issues/291). > > Best regards, > Thierry Boileau > > > I still don't know what the difference between my test and server > environments was, but for whatever reason on the server my persistence system > was storing my Date objects as java.sql.timestamp and my loca environment was > using java.util.Date. The problem, then is that ISO8601DateConverter only > converts date classes, not subclasses. But this isn't as easy a fix as it > first appears: > > - First Subclass ISO8601DateConverter to convert all subclasses of > java.util.Date. One would think this would be enough: > > public static ISO8601DateConverter DATE_CONVERTER = new > ISO8601DateConverter() { > @Override > public boolean canConvert(Class type) { > return Date.class.isAssignableFrom(type); > } > }; > > - At this point, XStream uses that converter, but for some reason, it retains > the class="sql-timestamp​" annotation, which no longer makes sense for that > converter. Now, if you use xstream to convert back, it will use the wrong > converter to convert the date back, an throw an excpetion. This code seems to > fix that: > > protected XStream createXstream(MediaType mediaType) { > XStream ret = super.createXstream(mediaType); > > ret.addDefaultImplementation(java.sql.Date.class,java.util.Date.class); > > ret.addDefaultImplementation(java.sql.Timestamp.class,java.util.Date.class); > > ret.addDefaultImplementation(java.sql.Time.class,java.util.Date.class); > ret.registerConverter(DATE_CONVERTER); > return ret; > } > > Obviously, this is an xstream issue, but since I first posted here, I thought > I would post the solution. Also, it would be nice if there was an easier > wayto change restlet converters since that was another hoop I had to jump > through in figuring this out. > > bjorn > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2938035 > ----------------------------- Bjorn Roche http://www.xonami.com Audio Collaboration http://blog.bjornroche.com ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2945413

