Object fails to get deserialized when returning back to WebFluxTest context

79 views Asked by At

I am writing unit tests for my API controller, on one of the tests - i am facing a problem of deserializing an object when it returns from the endpoint, when debugging it in the controller's function i see that everything goes as expected but the error is being thrown on expectBody(UserDto.class)

It works in production but throws error on test context

        String Id = "123";
        UserTimestampDto userTimestampDto = new             UserTimestampDto(LocalDateTime.now().toString());
        TimestampsDto timestampsDto = new TimestampsDto(userTimestampDto, userTimestampDto);
        UserDto userDto = new UserDto("123",timestampsDto);

        webTestClient
                .get()
                .uri(uriBuilder -> uriBuilder
                        .path(UserController.BASE_URL + "/" + Id)
                        .build())
                .accept(MediaType.APPLICATION_JSON)
                .exchange()
                .expectStatus().isOk()
                .expectBody(UserDto.class)
                .value(userItem -> userItem, equalTo(userDto));

The Error:

org.springframework.core.codec.DecodingException: JSON decoding error: Cannot construct instance of com.project.v1.model.timestamps.UserTimestampDto (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.project.v1.model.timestamps.UserTimestampDto (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (org.springframework.core.io.buffer.DefaultDataBuffer$DefaultDataBufferInputStream); line: 1, column: 296] (through reference chain: com.project.v1.model.customer.UserDto["internalTimestamps"]->com.project.v1.model.timestamps.TimestampsDto["createdDate"])

0

There are 0 answers