I need to write a client code to call a method in a webservice and this is my client code.
@HystrixCommand
public List<Location> saveLocation (List<LocationDTO> locationDTO) {
HttpEntity<List<LocationDTO>> httpEntity = new HttpEntity<>(locationDTO);
ResponseEntity<List<Location>> response =
restTemplate.exchange(locationProperties.getBaseURL(),HttpMethod.POST,
httpEntity,new ParameterizedTypeReference<List<Location>>() {
});
return getResponseBody(response);
}
For which I write Junit to test this piece of code.
@Test
public void saveLocationTest() throws Exception {
List<LocationDTO> locationList = new ArrayList<>();
LocationDTO locationDTO = new LocationDTO();
locationList.add(locationDTO);
Location location = new Location();
location.setLocationID(100);
mockServer.expect(requestTo(baseURL)).andExpect(method(HttpMethod.POST))
.andRespond(withSuccess("{\"locationID\":100}",MediaType.APPLICATION_JSON));
List<Location> response = locationClient.saveLocation(locationList);
assertEquals(response, location);
}
But I get the following error when I run the Junit, which also means my client code is wrong.
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not >deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.ByteArrayInputStream@175b9425; line: 1, column: 1]
Rest Template and junit works fine if I just pass LocationDTO instead of List<LocationDTO>.Could anyone please help me with this?