So I followed the instructions on that thread. I added JodaTime to my project 
and used new ISO8601DateConverter(), as suggested by xstream. It's a bit 
verbose, but it works... locally, it does not work when I deploy to the server. 
Obviously I have some difference between my deployment environment and my 
testing environment, but I can't figure out what. One of the things I like 
about Heroku (and HATED about GAE) is how similar test and deploy environs are, 
so I'm kinda baffled. Any hints about what the difference might be? some 
relevant code snips below. setupConverters() gets called as almost the first 
line of code, before any other part of restlet is setup.

bjorn

public static ISO8601DateConverter DATE_CONVERTER = new ISO8601DateConverter() {
            @Override
                public String toString(Object obj) {
                String str = super.toString(obj);
                // prints out when testing locally, but not on the server
                System.out.println( "=========> " + obj.toString() + " 
========> " + str );
                return str;
            }
        };


        private static void setupConverters() {
                Engine.getInstance().getRegisteredConverters().add(0,new 
MyXstreamConverter());
        }
        static class MyXstreamConverter extends XstreamConverter {
                @Override
                protected <T> XstreamRepresentation<T> create(MediaType 
mediaType, T source) {
                return new MyXstreamRepresentation<T>(mediaType, source);
            }
                @Override
                protected <T> XstreamRepresentation<T> create(Representation 
source) {
                return new MyXstreamRepresentation<T>(source);
            }
        }
        static class MyXstreamRepresentation<T> extends XstreamRepresentation {

                public MyXstreamRepresentation(MediaType mediaType, T source) {
                        super(mediaType, source);
                }
                public MyXstreamRepresentation(Representation source) {
                        super(source);
                }
                @Override
                protected XStream createXstream(MediaType mediaType) {
                        XStream ret = super.createXstream(mediaType);
                        ret.registerConverter(DATE_CONVERTER);
                        return ret;
                }
        }



> My xstream restlet code used to output time/date formats in ISO 8601.
> 
> Right now I seem to be getting dates like this:
> 
> <cTime class="sql-timestamp">2012-03-17 20:44:00.49</cTime>
> 
> It's not even clear what timezone that's in, so as far as I'm concerned 
> that's useless.
> 
> Not sure why this has changed, (Not too long ago, I ported my code from GAE 
> to Heroku and did some updates and so on, so a lot has changed) but maybe I'm 
> misremembering.
> 
> I see this thread: 
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2416505
> 
> but that seems really complex. I'm wondering if there's another way to change 
> the date formats output by xstream in restlet, especially since I remember it 
> did it another way before. (although, again, I might be misremembering)
> 
> Thanks!
> 
> bjorn

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2937785

Reply via email to