0

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?

Vish
  • 3
  • 4
  • Possible duplicate of [Can not deserialize instance of java.util.ArrayList out of START\_OBJECT token from my main pojo class, for type POJO elements](https://stackoverflow.com/questions/28613783/can-not-deserialize-instance-of-java-util-arraylist-out-of-start-object-token-fr) – xyz Jul 22 '17 at 12:49
  • Possible duplicate of https://stackoverflow.com/questions/14588727/can-not-deserialize-instance-of-java-util-arraylist-out-of-value-string – xyz Jul 22 '17 at 12:50

0 Answers0