java - Date changed after serialize Object to String with Jackson Json -
i litte bit confused. need serialize object json string. use jackson
library.
my pojo class stage
has attribute fromdate
, util.date
.
public class stage { @jsonformat(shape = jsonformat.shape.string, pattern = "dd.mm.yyyy", timezone="utc+1") private date fromdate; ...
before serialization fromdate has value: wed may 11 00:00:00 cest 2016
.
my serialize method looks this:
public static string serialize(stages stages) throws jsonprocessingexception { objectmapper objectmapper = new objectmapper(); string s = objectmapper.writevalueasstring(stages); return s; }
but after serialize object datefrom in json string hast value: ..."fromdate":"10.05.2016"...
. date wrong.
i used pattern of @jsonformat
, tried objectmapper
configuration.
public static string serialize(stages stages) throws jsonprocessingexception { objectmapper objectmapper = new objectmapper(); simpledateformat dateformat = new simpledateformat(util.sdf_dd_mm_yyyy); objectmapper.setdateformat(dateformat); dateformat.settimezone(timezone.gettimezone("utc+1")); string s = objectmapper.writevalueasstring(stages); return s; }
but date not expected one: ..."fromdate":"11.05.2016"...
what wrong?
i think timezone issue. serialized date looks it's in utc (?), it's correct you're seeing 10.05, cause 2016-11-05 00:00 utc+1 2016-10-05 23:00 utc..
you should try adapting code you're reading serialized value take account timezone date has been serialized in.
Comments
Post a Comment