JiBX – java.util.Date – Marshalling and UnMarshalling (TimeZone)

In XML schema we cannot specify the timezone for date field. In XML message we can populate time with or without the timezone component.

JiBX is smart to take care of the timezone component when marshalling and unmarshalling date type field that mapped to java.util.Date.

Lets say i have field or attribute like messageDate=”2001-12-17T09:30:47″ in XML message. Since there is not timezone specified Jibx assumes its in UTC. My server is running in CST, So when JiBX converts the request in java util data object. Its populated like this Mon Dec 17 03:30:47 CST 2001. The CST is -6:00 from UTC. So this is correct. There is not need to do any manual conversion. Some may consider this as defect but this is not.

Lets  says the same attribute is sent in XML as messageDate=”2001-12-17T09:30:47-06:00″. This time XML attribute has the timezone component. When JiBX unmarshall it convert it to Date object Mon Dec 17 09:30:47 CST 2001. For may this easy to understand then example above.

JIbx when marshall \ serialize java.util.Date object to XML, it convert it to date (in whichever timezone it is) in UTC. As per XML standard add Z to add of it

So in first case Mon Dec 17 03:30:47 CST 2001 get serializes to messageDate=”2001-12-17T09:30:47Z”

In second case this Mon Dec 17 09:30:47 CST 2001 get serializes to messageDate=”2001-12-17T15:30:47Z” 

In both case we had time in CST timezone (6 hours behind UTC) when it got serialized it converted to UTC so 6 horus are added. 

More details on other date type – look at JiBX http://jibx.sourceforge.net/binding/date-time.html


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s