0
votes

I try to call an url who accept to list.

Data sent is

{"contactAvailableIdList":["1"],"contactIdList":["2","3"]}


Method on the server
@RequestMapping(value = "/lodgers/{lodgerId}/associate/dissociate/contact", method = RequestMethod.PUT)
public void associateLodgerAndContact(@PathVariable("lodgerId") Long lodgerId, @RequestBody @Valid final List<Long> contactIdList, @RequestBody @Valid final List<Long> contactAvailableIdList) {
    lodgerService.associateDissociateLodgerAndContact(lodgerId, contactIdList, contactAvailableIdList);
}

"{"timestamp":1445958336633,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@5a1edae4; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@5a1edae4; line: 1, column: 1]","path":"/rest/lodgers/1/associate/dissociate/contact"}"

1

1 Answers

2
votes

Well I am not sure, if you can accept more requestbodies at once.

Standard way would be to have class

public class Contact{
  List<Long> contactIdList;
  List<Long> contactAvailableIdList;
}

And then accept it as

@RequestBody @Valid Contact contact

Also you are receiving array of string and you try to save them to array of Long. I am not sure either, if jackson tries implicitly to transform string elements of array to long in such case.