public class NotesApplicationTest {
@ClassRule
public static final DropwizardAppRule<NotesConfiguration> APP = new DropwizardAppRule<>(
NotesApplication.class,
ResourceHelpers.resourceFilePath("test-config.yml")
);
private final String BASE_URI = String.format("http://localhost:%d", APP.getLocalPort());
@Test
public void shouldGetNotes() {
Response response = APP.client()
.target(BASE_URI + "/notes/1")
.request(MediaType.APPLICATION_JSON_TYPE)
.get();
assertThat(response.getStatus()).isEqualTo(200);
NoteResponse note = response.readEntity(NoteResponse.class); // this line throws error
}
}Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.time.LocalDate out of START_ARRAY token
at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@28b286c0; line: 1, column: 16] (through reference chain: anttipp.notes.rest.api.NoteResponse["date"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:270)
at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1234)@Before
public void before() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
JacksonJsonProvider provider = new JacksonJsonProvider();
provider.setMapper(objectMapper);
APP.client().register(provider);
}@ClassRule
public static final DropwizardAppRule<NotesConfiguration> APP = new DropwizardAppRule<NotesConfiguration>(
NotesApplication.class,
ResourceHelpers.resourceFilePath("test-config.yml")
) {
@Override
protected JerseyClientBuilder clientBuilder() {
final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
jsonProvider.setMapper(getObjectMapper());
return new JerseyClientBuilder()
.property(ClientProperties.CONNECT_TIMEOUT, 1000)
.property(ClientProperties.READ_TIMEOUT, 5000)
.register(jsonProvider);
}
};