用杰克逊反序列化不好

Bad deserialize with jackson

我试着打电话给接受列表的 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":"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"}"

嗯,我不确定,如果你能一次接受更多的请求体。

标准方法是 class

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

然后接受为

@RequestBody @Valid Contact contact

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