Hi Tim,

The good news is that the SqlDate:default conversion is supposed to be doing what you want, since java.sql.Date is defined in terms of the local time zone. Unfortunately, the Java date code doesn't appear to follow it's own JavaDoc descriptions. I looked into this and found that the conversions I was doing were not resulting in the correct java.sql.Date values, so I've worked around the java.sql.Date problems in the CVS. The workaround is ugly, and means that historical dates prior to the Gregorian calendar switchover will not be handled properly (since I had to use a Calendar instance, which makes assumptions about date switchovers that don't match XML dates), but at least this should be usable for the vast majority of developers.

 - Dennis

Bornholtz, Tim wrote:

OK, so after digging a bit more I think this is a timezone issue.

If I write: System.out.println("GMT: " + disbDate.toGMTString());
I get: "GMT: 1 Jul 2003 00:00:00 GMT"


How have others dealt with this issue?  Since all dates in XML are supposed to 
be GMT I think the behavior of JiBX is correct.  I suppose it takes more care 
in creating dates in the system to make sure that time zones aren't used.

Any thoughts would be appreciated.

-Tim


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Bornholtz,
Tim
Sent: Wednesday, December 07, 2005 1:49 PM
To: jibx-users@lists.sourceforge.net
Subject: RE: [jibx-users] Unmarshaling dates


Nope, that didn't help. I tried the datatype of java.sql.Date with no difference. I also tried to change to the format of Date:default. I then had to append T00:00:00 to my dates but I still get the date of 6/30/2003 when the date in my XML is 7/1/2003 (July 1).

I created a minimal project with only one field in the XML and it is giving the same results.

Here are the actual complete files that I'm using. (Sorry if this message gets too big)

Any idea would be greatly appreciated.

-Tim

SampleDisbursement.xml (Source XML document)
<?xml version="1.0" encoding="UTF-8"?>
<Disbursement>
        <DisbursementDate>2003-07-01T00:00:00</DisbursementDate>
</Disbursement>


DisbursementBinding.xml (JiBX Binding file)
<binding>
        <mapping name="Disbursement" class="Disbursement">
<value name="DisbursementDate" field="actualDate" format="Date:default"/>
        </mapping>
</binding>


Disbursement.java (object to bind to)
import java.util.Date;

public class Disbursement {
        private Date    actualDate;

        public Date getActualDate() {
                return actualDate;
        }

        public void setActualDate(Date actualDate) {
                this.actualDate = actualDate;
        }
}


Test.java (sample program to run it)
import java.io.FileInputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;

public class Test {

        public static void main(String[] args) {
                IBindingFactory factory;
                try {
factory = BindingDirectory.getFactory(Disbursement.class);
                } catch (JiBXException e) {
                        e.printStackTrace();
                        return;
                }

                IUnmarshallingContext uctx;
                try {
                        uctx = factory.createUnmarshallingContext();
                    Object obj = uctx.unmarshalDocument
(new FileInputStream("xml/SampleDisbursement.xml"), null);
                    Disbursement disb = (Disbursement)obj;
Date disbDate = disb.getActualDate();
                    System.out.println("Month: " + disbDate.getMonth());
                    System.out.println("Day: " + disbDate.getDay());
                    System.out.println("Date: " + disbDate.toString());

IMarshallingContext mctx = factory.createMarshallingContext();
                    mctx.setIndent(4);
mctx.marshalDocument(obj, "UTF-8", null, System.out);
                } catch (Exception e) {
                        e.printStackTrace();
                        return;
                }       
        }
}


Output of Test.java:
Month: 5
Day: 1
Date: Mon Jun 30 20:00:00 EDT 2003
<?xml version="1.0" encoding="UTF-8"?>
<Disbursement>
   <DisbursementDate>2003-07-01T00:00:00</DisbursementDate>
</Disbursement>




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Dominik
Wei-Fieg
Sent: Tuesday, December 06, 2005 9:18 AM
To: jibx-users@lists.sourceforge.net
Subject: Re: [jibx-users] Unmarshaling dates


Hi, I haven't looked into the sources, but this somehow looks like a timezone problem. Have you tried to use java.sql.Date instead of
java.util.Date for the
attribute or Date.default as format?

Just my 2c
--
Dominik

--- Ursprüngliche Nachricht ---
Von: "Bornholtz, Tim" <[EMAIL PROTECTED]>
An: <jibx-users@lists.sourceforge.net>
Betreff: [jibx-users] Unmarshaling dates
Datum: Mon, 5 Dec 2005 16:31:53 -0500

I'm brand new to JiBX and am trying to get a small sample
working and have
a weird date marshaling problem.
My XML looks like this:

<Disbursement Number="1">
        <DisbursementDate>2003-07-01</DisbursementDate>
        <!-- more fields here ... -->
</Disbursement>

My Binding XML looks like this:

<binding>
        <mapping name="Disbursement" class="Disbursement">
                <value name="DisbursementDate" field="actualDate"
format="SqlDate:default"/>
                <!-- More value tags here to match XML -->
        </mapping>
</binding>

and my java source has the "actualDate" field defined as a
java.util.Date.
When I load the XML into a sample program and run the code:
System.out.println("Date: " + disb.getActualDate());

I get the output of Date: 2003-06-30


But my input date was July 1, 2003. Whatever I use for a
date the output
is one day earlier. If I marshal the object back into XML
and then write
that the correct value is back (2003-07-01).

What am I doing wrong?

Thanks,
Tim


--
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&opÌk
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to