I have found this two:
Jackson Object Mapper in spring MVC not working
why is the Object Mapper date fromat not used by message converters for date transform?
but none are the solution for me.
Spring MVC xml:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.xxx.model.MyJacksonObjectMapper">
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
MyJacksonObjectMapper:
public class MyJacksonObjectMapper extends ObjectMapper {
private static final long serialVersionUID = -3282890427623599460L;
public MyJacksonObjectMapper() {
super();
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
}
}
Not matter I change register-defaults
to true or false, it is still not working, my controller always serialize the object's date value in timestamp (long) format.
My POJO object is not appended with any annotation, it is plain POJO and I cannot annotate it with any annotation (not my class), I believe there must be config to allow serialize default object's date in desired format, but it is not working, please help.
Dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>