restTemplate.put在更新包含列表的数据时给出了 "Can not deserialize instance of java.util.ArrayList out of START_OBJECT"。

问题描述 投票:0回答:1

我的代码片段如下。

    ArrayList<String> list1 = new ArrayList();
    list.add("test");
    Map<String, List> params = new HashMap<String, List>();
    params.put("1", list1);     
    HttpHeaders headers = new HttpHeaders();        
    headers.setContentType(MediaType.APPLICATION_JSON);       
    HttpEntity<String> entity = new HttpEntity<>(params,headers );
    restTemplate.put(uri, entity);

得到的响应是 "Can not deserialize instance of java.util.ArrayList out of START_OBJECT token/\".有没有人遇到类似的问题?

java spring-boot resttemplate
1个回答
3
投票

你可以将 MapJson 字符串,然后传递给实体。

String paramsString = new Gson().toJson(params);
HttpEntity<String> entity = new HttpEntity<>(paramsString,headers);
restTemplate.put(uri, entity);
© www.soinside.com 2019 - 2024. All rights reserved.