杰克逊无法将json转换为地图列表

时间:2018-09-20 12:56:31

标签: java json spring-boot jackson

在我的spring-boot项目中,我有一个控制器

@RequestMapping(path = { "/multiCommunication" }, consumes = {
        MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
ResponseEntity<Object> multiCommunication(ArrayList<HashMap<String, String>> listOfInput){ //code}

我无法访问列表,因为杰克逊无法投放我的请求。

请求:

  

[     {       “ type”:“ HPMRE”,       “ pipFirstName”:“ ABC”     },     {       “ type”:“ HPMRE”,       “ pipFirstName”:“ XYZ”     }   ]

JSON是否有问题?

我尝试制作一个模型类,其变量类型为ArrayList<HashMap<String, String>>,但jackson仍无法强制转换。

2 个答案:

答案 0 :(得分:1)

尝试一下

@RequestMapping(path = { "/multiCommunication" }, consumes = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST) ResponseEntity<Object> multiCommunication(ArrayList<LinkedHashMap<String, String>> listOfInput){

答案 1 :(得分:0)

尝试将HashMap更改为LinkedHashMap:

@RequestMapping(path = { "/multiCommunication" }, consumes = {
        MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
ResponseEntity<Object> multiCommunication(ArrayList<LinkedHashMap<String, String>> listOfInput){ 
//code
}