java - Jackson JSON - Strip Timezone from Calendar object while deserializing -
i have jackson deserializer convert date in json string calendar object. passing "2015-10-22" in request , gets converted "2015-10-22-04:00" after convert calendar object. there way suppress timezone being sent? in scenarios use xmlgregoriancalendar , using "date.settimezone(datatypeconstants.field_undefined)" suppress timezone.
private static simpledateformat formatter = new simpledateformat("yyyy-mm-dd"); @override public calendar deserialize(jsonparser jsonparser, deserializationcontext arg1) throws ioexception, jsonprocessingexception { // todo auto-generated method stub string datestring = jsonparser.gettext(); try { calendar calendar = calendar.getinstance(); calendar.settime(formatter.parse(datestring)); return calendar; } catch (parseexception e) { throw new runtimeexception(e); } }
no timezone sent, question "is there way suppress timezone being sent?" meaningless.
the calendar.getinstance() method assigns default timezone, see javadoc:
gets calendar using default time zone , locale.
calendarreturned based on current time in default time zone default locale.
you replace "current time" call settime(), time zone , locale remain unchanged.
a calendar object always have time zone , locale.
Comments
Post a Comment