I am using LocalDateTime in my model, after including LocalDateTimeDeserializer, converted the bean field to
@NotNull
@Column(name = "created")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime created;
and included the
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false
property in the SpringBoot's application.properties file, the application is finally able to deserialize the JSON and show properly like,
"created": "2018-04-22T21:21:53.025",
But, when I am doing testing, it ignores the WRITE_DATES_AS_TIMESTAMPS flag, I guess and generates an output for the same string date above like,
"created":{"year":2018,"monthValue":4,"month":"APRIL","dayOfMonth":22,"dayOfYear":112,"dayOfWeek":"SUNDAY","hour":21,"minute":23,"second":16,"nano":986000000,"chronology":{"id":"ISO","calendarType":"iso8601"}}
Please, note that including the property in application.properties in test resources folder did not change anything.
My test configuration looks like,
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration
@Category(IntegrationTest.class)
public class ApplicationTests {
....
Do you have any idea on what I am doing wrong?
I had the same issue and the below solution worked for me,
add the below code in your Applicationtests class
If you want to support your own date formats then add the formatters as well, //the below customisation is required if you need to support different date formats
Where the custom classes will looks like,
and