正如标题所述,我在为其余模板设置参数时遇到麻烦。
首先,这是代码:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("place_id","7" );
params.add("name","Winsrow" );
params.add("phone","111333222" );
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", AUTHORIZATION);
headers.add("Content-Type", "application/json");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
String response = restTemplate.postForObject(CREATE_SHIPMENT_URL, request, String.class);
我使用字符串作为响应只是为了消耗WS响应。这是问题所在:
RestTemplate在过程的某个时刻,正在将我的参数映射(没有键)的值转换成具有单个对象(此对象包含映射键的值)的数组,如下所示(在服务器端):
$info = object(stdClass) {
place_id => array(
(int) 0 => '7'
)
name => array(
(int) 0 => 'Winsrow'
)
phone => array(
(int) 0 => '111333222'
)
我该怎么做才能防止这种转变? 干杯!