Fix thread-safety issue in DateSerializer.

This commit is contained in:
Jonathan Wood 2015-06-25 09:21:36 -07:00
parent 1216a009cb
commit b729e450ab

View file

@ -8,7 +8,6 @@ import java.util.GregorianCalendar;
class DateSerializer implements Serializer {
static final Serializer DATE_SERIALIZER = new DateSerializer();
private static final Calendar calendar = new GregorianCalendar();
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:m:ss");
@Override
public boolean canSerialize(Object value) {
@ -17,6 +16,7 @@ class DateSerializer implements Serializer {
@Override
public void serialize(Object value, SerializerContext context) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:m:ss");
context.serialized.append(dateFormat.format(value));
int tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
context.serialized.append(String.format("%+03d:%02d", tzOffset / 60, tzOffset % 60));