You will need to implement your own Dateserializer, as well as the following (received this from the tutorial , so props to Loiane, not me ;-)):
package ....util.json; import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.map.JsonSerializer; import org.codehaus.jackson.map.SerializerProvider; import org.springframework.stereotype.Component; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; @Component public class JsonDateSerializer extends JsonSerializer<Date>{ private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm ");
then you can simply add the following annotation to your Date-Objects and it will persist normally:
@JsonSerialize(using = JsonDateSerializer.class) public Date getCreated() { return created; }
At least it works with spring 3.2.4 and jackson 1.9.13.
edit: Think about using FastDateFormat instead of SimpleDateFormat , for it is an alternative to threadsafe-alternative (as indicated in the comments of the Loianes article)
source share