|
I wrote specific handlers for date fields (actually i
copied and modified an earlier post suggesting this approach)... such
as:
public class DateOnlyDateHandler extends
GeneralizedFieldHandler {
private static final String FORMAT =
"yyyy-MM-dd";
private static SimpleDateFormat sFormatter = new SimpleDateFormat(FORMAT); public DateOnlyDateHandler() { }
public static String getFormat()
{
return FORMAT; } public static SimpleDateFormat getFormatter()
{
return new SimpleDateFormat(FORMAT); } /**
* This method is used to convert the value when the getValue method * is called. The getValue method will obtain the actual field value * from given 'parent' object. This convert method is then invoked * with the field's value. The value returned from this * method will be the actual value returned by getValue method. * * @param value the object value to convert after performing a get * operation * @return the converted value. */ public Object convertUponGet(Object value) { if (value == null) { return null; } Date date = (Date) value; synchronized (sFormatter) { String result = sFormatter.format(date); return result; } } /**
* This method is used to convert the value when the setValue method * is called. The setValue method will call this method to obtain * the converted value. The converted value will then be used as * the value to set for the field. * * @param value the object value to convert before performing a set * operation * @return the converted value. */ public Object convertUponSet(Object value) { Date date = null; try { synchronized (sFormatter) { date = sFormatter.parse((String) value); } } catch (ParseException px) { throw new IllegalArgumentException(px.getMessage()); } return date; } /**
* Returns the class type for the field that this GeneralizedFieldHandler * converts to and from. This should be the type that is used in the * object model. * * @return the class type of of the field */ public Class getFieldType() { return Date.class; } /**
* Creates a new instance of the object described by this field. * * @param parent The object for which the field is created * @return A new instance of the field's value * @throws IllegalStateException This field is a simple type and * cannot be instantiated */ public Object newInstance(Object parent) throws IllegalStateException { //-- Since it's marked as a string...just return null, //-- it's not needed. return null; } From: Stephen Burrows [mailto:[EMAIL PROTECTED] Sent: Friday, April 08, 2005 8:36 AM To: '[email protected]' Subject: [castor-dev] How to suppress TimeZone offset when Marshalling java.util.date Hi All, Does anyone know of a way to suppress timeZone offsets
when marshalling a java.util.Date. We unmarshall the following
field <dlx:FlightSegment DepartureDateTime="2005-06-04T11:45:00.000"
ArrivalDateTime="2005-06-03T22:30:00.000+01:00"
ResBookDesigCode="Y" RPH="0" FlightNumber="9566"
NumberInParty="1"> Then marshall back and the castor marshaller adds the
daylight saving timezone offset of +01:00 to the DepartureDateTime field. <dlx:FlightSegment DepartureDateTime="2005-06-04T11:45:00.000+01:00"
ArrivalDateTime="2005-06-03T22:30:00.000+01:00"
ResBookDesigCode="Y" RPH="0" FlightNumber="9566"
NumberInParty="1"> This causes problems when we pass messages between machines in different
timezones , as the marshaller Adjusts the timezone accordingly and changes the
time Example below > Request from time zone
A: > <dlx:FlightSegment
DepartureDateTime="2005-06-04T11:45:00.000+01:00"
>
ArrivalDateTime="2005-06-03T22:30:00.000+01:00" ResBookDesigCode="Y"
> RPH="0"
FlightNumber="9566" NumberInParty="1"> > Server Response from
time zone B: > <ns2:FlightSegment
DepartureDateTime="2005-06-04T20:45:00.000+10:00"
>
ArrivalDateTime="2005-06-04T07:30:00.000+10:00" ResBookDesigCode="Y"
> RPH="0"
FlightNumber="9566" NumberInParty="1"> DepartureDateTime has changed L Any suggestions.? Regards, Stephen Burrows |
- [castor-dev] How to suppress TimeZone offset when Marshall... Stephen Burrows
- RE: [castor-dev] How to suppress TimeZone offset when... Andrew Fawcett
- RE: [castor-dev] How to suppress TimeZone offset when... Jay Goldman
- RE: [castor-dev] How to suppress TimeZone offset ... Werner Guttmann
- RE: [castor-dev] How to suppress TimeZone offset ... Werner Guttmann
- RE: [castor-dev] How to suppress TimeZone offset ... Werner Guttmann
- RE: [castor-dev] How to suppress TimeZone offset ... Werner Guttmann

