I am trying to set a List<Long> to an Java object.
The set function is:
ResponseEntity<String> response = bcInsertService.addNewClip(new PrmBcClipInsert()
.setTags(Arrays.asList(new Long[]{5L, 3L}))
);
And the object is
public class PrmBcClipInsert implements Serializable {
@ApiModelProperty(required = true)
private List<Long> tags;
public List<Long> getTags() {
return tags;
}
public PrmBcClipInsert setTags(List<Long> tags) {
this.tags = tags;
return this;
}
}
This is BcInsertService:
public class BcInsertService extends RestTemplate {
private static final Logger log = LoggerFactory.getLogger(BcInsertService.class);
public ResponseEntity<String> addNewClip(PrmBcClipInsert prmBcClipInsert) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> map= new LinkedMultiValueMap<String, Object>();
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(prmBcClipInsert.getParameters(), headers);
ParameterizedTypeReference<StandardResponse> typeRef = new ParameterizedTypeReference<StandardResponse>() {};
ResponseEntity<String> response = this.postForEntity( "http://localhost:8080/bc/add-clip", request , String.class );
log.info(response.toString());
return response;
}
}
And it returns an error:
Field error in object 'prmBcClipInsert' on field 'tags': rejected value [[5,3]]; codes [typeMismatch.prmBcClipInsert.tags,typeMismatch.tags,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [prmBcClipInsert.tags,tags]; arguments []; default message [tags]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'tags'; nested exception is java.lang.NumberFormatException: For input string: "[5,3]"]
Why the method doesn't accept a list even though it says that it accepts a list?
addNewClip(new PrmBcClipInsert().setTags(Arrays.asList(5L, 3L)));? Isn't that the whole point of returningthisfrom setTags()?getParameters()method in your postedPrmBcClipInsertclass, so this code is not the code producing the posted error.