json - Jackson Serialization sometimes borking with timezone -


(i in utc+2 timezone, assume 2 hour difference).

i'm busy writing json restful api that's part of grails application (2.0.3 on project in particular, problem occurs in other versions). use jackson serialization , deserialization of json, , jsonservice's configuration looks this: http://pastebin.com/jacytmuf

so multiple domain objects have values collated , represented in single dto (in case it's simple map), , these passed jsonservice convert json, returned (to request). of fields serialized correctly, exception of 2 of (several) dates, off 2 hours. can example run:

  db_dev=# select next_billing_date account code = 'cats001';   next_billing_date   ---------------------  2013-06-20 00:00:00 

and verified correct (within memory) little action

def checktimezone() {         account acc = account.findbycode("cats001")         log.error(acc.nextbillingdate)     } 

which returns

error mash.testcontroller  - 2013-06-20 00:00:00.0 

as expected. furthermore, can check nothing tampers in-memory value doing, within restaccountcontroller:

def show() {          ...          def ans = [ code: ac.code, nextbillingdate: ac.nextbillingdate ]           log.error("cattttssssssssssssss::::: ${ac.nextbillingdate}")          [ans: ans]     } 

(returning)

error mash.restaccountcontroller  - cattttssssssssssssss::::: 2013-06-20 00:00:00.0 

yet when hit relevant endpoint, get:

nextbillingdate": "2013-06-19t22:00:00.000+0000" 

which off 2 hours. nextbillingdate property normal java date object, underlying database psql:

next_billing_date           | timestamp without time zone | not null  | plain    |  

and hence bit lost ideas on why it's randomly deducting 2 hours. can see why 2 hours magic number (timezone differences), cannot explain why it's offsetting date on objects (or indeed on subset of date objects).

few things check:

  1. is jvm set utc timezone default?
  2. is timezone in database row utc? in case don't think db cares timezone.

option:

if jvm set utc default then, see offset of 2 hours. in order timestap in zone utc+2:00 can set default timezone zone below in bootstrap.groovy

timezone.setdefault(timezone.gettimezone("gmt+2:00"))

note:- refer gmt vs utc find difference.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -