1

Need to add list of objects with errors to an arraylist body. code where I'm trying to set response.getErrors() to response.getBody():

String jsonResponse = restTemplate.postForObject(url, requestBody, String.class);
JavaType valueType = mapper.getTypeFactory().constructParametricType(ResponseContainer.class, type);
ResponseContainer<ResponseType> response = mapper.readValue(jsonResponse, valueType);
        // TODO if error != null put errors to body
if (response.getErrors() != null) {
    response.getBody().addAll(response.getErrors());
}
return response.getBody();

Model class:

@ApiModelProperty(notes = "Список параметров сообщения")
List<T> body = new ArrayList<T>();

@ApiModelProperty(notes = "Список ошибок")
List<ResponseError> errors;

Error is:

Error:(70, 35) java: no suitable method found for add(java.util.List<com.infin.it.integrator.impl.base.ResponseError>)
method java.util.Collection.add(ResponseType) is not applicable
  (argument mismatch; java.util.List<com.infin.it.integrator.impl.base.ResponseError> cannot be converted to ResponseType)
method java.util.List.add(ResponseType) is not applicable
  (argument mismatch; java.util.List<com.infin.it.integrator.impl.base.ResponseError> cannot be converted to ResponseType)

1 Answers1

0

I changed type of @ApiModelProperty(notes = "Список ошибок") List<ResponseError> errors; to List<T> errors = new ArrayList<T>(); Soon i added fields that came from response to my ResponseBaseModel.class, to take that fields and show an error.

That's solved my problem. Thanks for all to advices.