0

我尝试调用一个接受列表的 url。

发送的数据是

{"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":"无法读取文档:可以不在 [Source: java.io.PushbackInputStream@5a1edae4; 的 START_OBJECT 令牌中反序列化 java.util.ArrayList 的实例;行:1,列:1];嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize an instance of java.util.ArrayList out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@5a1edae4; 行:1,列:1]","路径":"/rest/lodgers/1/associate/dissociate/contact"}"

4

1 回答 1

2

好吧,我不确定您是否可以一次接受更多请求体。

标准方式是上课

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

然后接受它为

@RequestBody @Valid Contact contact

此外,您正在接收字符串数组,并尝试将它们保存到 Long 数组中。我也不确定,如果杰克逊在这种情况下隐式尝试将数组的字符串元素转换为 long。

于 2015-10-27T15:19:51.837 回答