1

I'm testing a REST controller in Spring Boot with mockMvc. One of the request parameters has a property of type OffsetTime. When I use the following annotations:

@ExtendWith(SpringExtension.class)
@WebMvcTest(MyController.class)

the following condition in mockMvc is true: .andExpect(jsonPath("$.createdTime", is("2018-05-05T10:11:12.123+02:00")))

However, when I swith the annotations (because I have to use some extra converters) to:

@SpringBootTest
@AutoConfigureMockMvc

I get the following error in the test:

java.lang.AssertionError: JSON path "$.createdTime"
Expected: is "2018-05-05T10:11:12.123+02:00"
     but: was <1525507872.123000000>

In fact I don't want the timestamp in the SpringBootTest either, I want the latter to serialize the date in the "offset" format.

How can I achieve it? adding

spring:
  jackson:
    serialization:
      write-dates-as-timestamps: false

to application.yml did not change anything for the spring boot test.

Greg
  • 1,227
  • 5
  • 23
  • 52
  • This helped me with the same problem: https://stackoverflow.com/questions/69012206/incorrect-serialization-of-zoneddatetime-in-junit-tests-date-returns-as-double – jeremyt May 25 '22 at 11:34

0 Answers0