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

Reply via email to