changed synchronization on Date type adapter to be for the format object per code review comments on r452
This commit is contained in:
parent
907082102d
commit
fbefa59b66
|
@ -251,21 +251,22 @@ final class DefaultTypeAdapters {
|
||||||
|
|
||||||
// These methods need to be synchronized since JDK DateFormat classes are not thread-safe
|
// These methods need to be synchronized since JDK DateFormat classes are not thread-safe
|
||||||
// See issue 162
|
// See issue 162
|
||||||
public synchronized JsonElement serialize(
|
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
Date src, Type typeOfSrc, JsonSerializationContext context) {
|
synchronized (format) {
|
||||||
String dateFormatAsString = format.format(src);
|
String dateFormatAsString = format.format(src);
|
||||||
return new JsonPrimitive(dateFormatAsString);
|
return new JsonPrimitive(dateFormatAsString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Date deserialize(
|
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
if (!(json instanceof JsonPrimitive)) {
|
if (!(json instanceof JsonPrimitive)) {
|
||||||
throw new JsonParseException("The date should be a string value");
|
throw new JsonParseException("The date should be a string value");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return format.parse(json.getAsString());
|
synchronized (format) {
|
||||||
|
return format.parse(json.getAsString());
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new JsonParseException(e);
|
throw new JsonParseException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user