I have a very similar problem to this post: Rest Assured doesn't use custom ObjectMapper
However, I am using slightly different configurations/models and the provided answer did not solve my problem.
When running the mock mvc test, my custom ObjectMapper config is not getting picked up. I have tried attaching this config class to the RestAssuredMockMvc, but it still seems to not pick this up when the standalone setup fires.
Any ideas?
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public abstract class BaseClassForContractTests {
@Autowired
Controller controller;
@Before
public void setup() {
RestAssuredMockMvc.config = RestAssuredMockMvcConfig.config().objectMapperConfig(
ObjectMapperConfig.objectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {
@SuppressWarnings("rawtypes")
@Override
public ObjectMapper create(Class cls, String charset) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
//objectMapper.setTimeZone(TimeZone.getTimeZone("America/New_York"));
//objectMapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, true);
return objectMapper;
}
})
);
RestAssuredMockMvc.standaloneSetup(controller);
}
}