在我的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仍无法强制转换。
答案 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
}