杰克逊无法解析List <long> </long>

时间:2013-09-16 03:39:15

标签: java spring jackson

杰克逊将List<Long>解析为List<Integer>,因此我得到ClassCastException。其中一个解决方案是将参数作为List<String>,但我不想这样做。有人可以建议我另类吗?

@RequestMapping(value = "/device/deleteNote", produces = "application/json", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> deleteNotification(@RequestBody ArrayList<Long> notificationIdListParam) {
    ....
}

1 个答案:

答案 0 :(得分:5)

试试这个

final static ObjectMapper mapper = new ObjectMapper();

final List<Obj> instance = mapper.readValue(json, new TypeReference<List<Obj>>(){});