You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Ramaswamy, Muthu" <mr...@gers.com> on 2002/11/14 01:08:45 UTC

Date Serialization by Apache Client.

Hi All-

When I pass the Date with time component set to 00:00:00, Apache Client
after serialization adds 8:00 hours to the time portion?

Do I have specify any special format or is it due to some kind of bug in
serializer?. 

Here is a sample code I am using on the Axis Client
======================================

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String textDate = "2002-11-11";  //required 10/29/2002 7:20:59 PM.
Date requestDt = null;

try
{
   requestDt = sdf.parse(textDate);
}
catch (Exception e)
{
     System.out.println("Exception in Parsing Date");
}

When I pass the above date, after Serialization, the output is:
============================================
  
 <requestDt>2002-11-11T08:00:00.000Z</requestDt>

I would expect to see 2002-11-11T00:00:00.000Z . Appreciate any input to
resolve the problem.

Thanks.,

-Muthu

 

Re: Date Serialization by Apache Client.

Posted by Benjamin Tomasini <bt...@neteverything.com>.
Axis treats all dates coming into its serializer / deserializer as GMT,
and skews it to you time zone.

The only way, other than writing your own serializer, is to skew values
in and out on the server side.

Here is the hack that I used:  Anyone with a better idea?

Basically perform these functions *server side* on all instance
variables before sending over SOAP, or after receiving from SOAP.

    /**
     * Fix an Axis date before it goes out to compensate for the 
     * serialization of a date to GMT
     */

    protected java.util.Date skewAxisDateOut(java.util.Date value) {

	if (value == null)
	    return null;

	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(value);
	cal.add(Calendar.MILLISECOND, cal.get(Calendar.ZONE_OFFSET));
	cal.add(Calendar.MILLISECOND, cal.get(Calendar.DST_OFFSET));
	return cal.getTime();

    }

    /**
     * Fix an Axis date after it comes in to compensate for the 
     * de-serialization of a date from GMT
     */

    protected java.util.Date skewAxisDateIn(java.util.Date value) {

	if (value == null)
	    return null;

	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(value);
	cal.add(Calendar.MILLISECOND, cal.get(Calendar.ZONE_OFFSET) * -1);
	cal.add(Calendar.MILLISECOND, cal.get(Calendar.DST_OFFSET) * -1);
	return cal.getTime();

    }

    

On Wed, 2002-11-13 at 16:08, Ramaswamy, Muthu wrote:
> Hi All-
> 
> When I pass the Date with time component set to 00:00:00, Apache Client
> after serialization adds 8:00 hours to the time portion?
> 
> Do I have specify any special format or is it due to some kind of bug in
> serializer?. 
> 
> Here is a sample code I am using on the Axis Client
> ======================================
> 
> SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
> String textDate = "2002-11-11";  //required 10/29/2002 7:20:59 PM.
> Date requestDt = null;
> 
> try
> {
>    requestDt = sdf.parse(textDate);
> }
> catch (Exception e)
> {
>      System.out.println("Exception in Parsing Date");
> }
> 
> When I pass the above date, after Serialization, the output is:
> ============================================
>   
>  <requestDt>2002-11-11T08:00:00.000Z</requestDt>
> 
> I would expect to see 2002-11-11T00:00:00.000Z . Appreciate any input to
> resolve the problem.
> 
> Thanks.,
> 
> -Muthu
> 
>