I haven't tried using the XStream annotations on any of my beans but it looks 
like this could be a good approach.  However, the hours service I developed 
also supports the serialization of beans to JSON (using a json library) and the 
hours services is part of a suite of services which serialize other beans into 
xml, json, iCal, etc.  so it doesn't feel right to introduce the XStream 
annotations into the beans but I'll give it a try.  

> -----Original Message-----
> From: Jairo de Almeida [mailto:[email protected]]
> Sent: Tuesday, February 07, 2012 5:23 AM
> To: [email protected]
> Subject: Re: [xstream-user] Using a Converter that will handle null
> values
> 
> Hi, John
> This sample using calendar works fine to date converter:
> http://pastebin.com/bEfk3aZy
> 
> Using reference in your beans with this annotation
>       @XStreamAlias("date")
>       @XStreamConverter(SingleValueCalendarConverter.class)
>       private Calendar  date;
> 
> Jairo.
> 
> 2012/2/6 John Fereira <[email protected]>:
> > I have been using XStream for quite a while without a hitch but
> recently was
> > presented with a use case that I'm not sure how to resolve.
> Essentially I
> > have an Hours object that represents the opening and closing hours of
> a
> > location.  The actual open/close fields are  "Time" objects that uses
> a
> > Calendar instance on the back end.   Up until recently the
> open/closed Time
> > objects were always instantiated to a non-null value.   However, for
> reasons
> > that I don't necessarily agree with I've been asked to set the
> open/closed
> > Time objects to a null if a flag (another field in the Hours object)
> has
> > been set to "closed all day" or "open all day".   The issue that I'm
> having
> > is that I want to serialize  the Hours object and marshall a
> "openTime"
> > element (with the time set to null)  even when the Time object is
> null.
> > I've got a "TimeConverter" class that returns true for the canConvert
> method
> > (it is recognizing that a Time.class is being handled) but it doesn't
> appear
> > that the marshal method is being called if the Time object is a null.
> 
> 
> 
> --
> Sem mais...
> Jairo de Almeida
> email: [email protected]
> msn: [email protected]
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to