Spring 坏的反序列化与杰克逊

Spring 坏的反序列化与杰克逊,spring,jackson,spring-rest,Spring,Jackson,Spring Rest,我尝试调用一个接受列表的url 发送的数据是 {"contactAvailableIdList":["1"],"contactIdList":["2","3"]} Method on the server @RequestMapping(value = "/lodgers/{lodgerId}/associate/dissociate/contact", method = RequestMethod.PUT) public void associateLodgerAndContact(@Pa

我尝试调用一个接受列表的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);
}
{“contactAvailableIdList”:[“1”],“contactIdList”:[“2”,“3”]}
服务器上的方法
@RequestMapping(value=“/lodgers/{lodgerId}/associate/dissection/contact”,method=RequestMethod.PUT)
public void associateLodgerAndContact(@PathVariable(“lodgerId”)长lodgerId、@RequestBody@Valid final List contactIdList、@RequestBody@Valid final List contactAvailableIdList){
lodgerService.AssociatedIsSociatelodgerand联系人(lodgerId、contactIdList、ContactAvailableId列表);
}
{“timestamp”:1445958336633,“status”:400,“error”:“Bad” 请求“,”异常“:”org.springframework.http.converter.httpmessagenoteradableexception“,”消息“:”可能 未读取文档:无法反序列化java.util.ArrayList的实例 [Source: java.io。PushbackInputStream@5a1edae4;行:1,列:1];嵌套 异常为com.fasterxml.jackson.databind.JsonMappingException:Can 未从START\u对象反序列化java.util.ArrayList的实例 令牌\n位于[源代码:java.io]。PushbackInputStream@5a1edae4;行:1, 列:1],“路径”:“/rest/lodgers/1/associate/dissection/contact”}”


嗯,我不确定,你是否能一次接受更多的请求

标准的方法是上课

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

另外,您正在接收字符串数组,并尝试将它们保存到Long数组。我也不确定jackson是否会在这种情况下隐式地将数组的字符串元素转换为long。

我改为使用一个类,但两个列表为null,而不是listList。如果必要,jackson会将JSON字符串强制转换为整数,除非配置设置明确禁止。
@RequestBody @Valid Contact contact