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: [email protected]
> 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: <[email protected]>
> > 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users