Deserializing ISODate objects from MongoDB into Java POJO -


i have existing data in mongodb formatted such:

"created_at" : isodate("2011-11-25t18:17:16z") 

when try deserialize java pojo using morphia, gives date system timezone applied date instead of gmt date.

/**  * class aggregationquerydetails.  */ public class aggregationqueryresulttriggeredpolicydetails {      /** triggered time. */     private date created_at;      /** event ids. */     private list<string> event_ids;       /**      * @return createdat      */     public date getcreatedat() {         return created_at;     }      /**      * @param createdat      *            createdat set      */     public void setcreatedat(date createdat) {         this.created_at = createdat;     } } 

how can avoid timezone conversion ?

internally java.util.date not store timezone. date internally represented in utc. format date timezone wish.

the behavior seeing due fact when "view" java.util.date either in debugger or printing it, shown in local timezone.

here's basic example of how format:

public static string iso_format = "yyyy-mm-dd't'hh:mm:ss.sss zzz"; private static final timezone utc = timezone.gettimezone("utc"); private static final simpledateformat isoformatter = new simpledateformat(iso_format); static {     isoformatter.settimezone(utc); } ...  public string tostring() {     return "mydate: " + isoformatter.format(mydate); } 

Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -