昨天晚上臨下班前寫了一個內部調用接口,在調用時發現了報了以下錯誤
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of out of START_ARRAY token
項目使用了Feign框架,,在被調用方看起來是正常。。被調用方controller層詳細代碼如下:
@Inner
@PostMapping("/getPileInfoList")
public R getPileInfoList(@RequestParam(value = "agentId",required = false) Long agentId,@RequestParam(value = "stationId",required = false) Long stationId,@RequestParam(value = "interconnectionFlag",required = false) Long interconnectionFlag){
R result = new R();
try {
result.setData(pileService.list(queryEntity));
return result;
}catch (Exception e){
log.error("查詢不攜帶槍信息的樁信息失敗:{}",e);
return result.setError(ResponseTypeEnum.GLOBAL_REQUEST_FAILED);
}
}
被遠程調用方的開放service如下:
/**
* @description: 查詢樁信息列表不包含槍信息
* @param
* @return
* @throws
* @author ckinghan
* @date 2020/5/6 18:33
*/
@PostMapping("/app/getPileInfoList")
R<PileListVo> getPileInfoList(@RequestParam(value = "agentId",required = false) Long agentId,@RequestParam(value = "stationId",required = false) Long stationId,@RequestParam(value = "interconnectionFlag",required = false) Integer interconnectionFlag, @RequestHeader(SecurityConstants.FROM) String from);
經詳細分析了一下錯誤信息及調用代碼,發現在遠程調用響應類中,添加響應泛型爲:PileListVo,而實際我在響應時並沒有返回這個泛型,響應的實際泛型是List,好吧。。更改被調用controller層代碼如下:
@Inner
@PostMapping("/getPileInfoList")
public R getPileInfoList(@RequestParam(value = "agentId",required = false) Long agentId,@RequestParam(value = "stationId",required = false) Long stationId,@RequestParam(value = "interconnectionFlag",required = false) Long interconnectionFlag){
R result = new R();
try {
PileListVo listVo = new PileListVo();
listVo.setPileEntityList(pileService.list(queryEntity));
result.setData(listVo);
return result;
}catch (Exception e){
log.error("查詢不攜帶槍信息的樁信息失敗:{}",e);
return result.setError(ResponseTypeEnum.GLOBAL_REQUEST_FAILED);
}
}
更改後問題解決。。
不細心造成的問題,,浪費近20分鐘時間 !(¥……¥)!
留個記錄,如果有出現相同問題的朋友可以做個參考。。