I have a simple simple Json serializer in my Spring project:
public class JsonDateTimeSerializer extends JsonSerializer<Date> { private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Override public void serialize(Date value, JsonGenerator gen, SerializerProvider sp) throws IOException { gen.writeString(DATE_FORMAT.format(value)); } }
And use it like:
@JsonSerialize(using = JsonDateTimeSerializer.class) public Date getDate() { return date; }
Should I take care of thread safety and make DATE_FORMAT synchronization (since SimpleDateFormat not thread safe)? I'm not sure how @JsonSerialize works - does it only create one serialized instance for all threads? Or does he create a separate instance for each conversion?
java json spring multithreading serialization
Laimoncijus Sep 05 '14 at 7:32 2014-09-05 07:32
source share