久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

HttpMessageConverter 異常:RestClientException:無(wú)法寫(xiě)入請(qǐng)

HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無(wú)法寫(xiě)入請(qǐng)求:找不到合適的 HttpMessageConverter) - IT屋-程序員
本文介紹了HttpMessageConverter 異常:RestClientException:無(wú)法寫(xiě)入請(qǐng)求:找不到合適的 HttpMessageConverter的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在編寫(xiě)一個(gè)客戶端來(lái)使用 RESTful 服務(wù).我需要以鍵值對(duì)的形式發(fā)送請(qǐng)求,他們建議我為此使用 Map.我調(diào)用的 RESTful 服務(wù)只會(huì)接受 JSON,而我的客戶端將使用 Java.它實(shí)際上將成為現(xiàn)有企業(yè) EJB 項(xiàng)目的一部分.

I am writing a client to consume a RESTful service. I am required to send the request in key, value pair, they suggested that I use a Map for this. The RESTful service that I am calling is only going to accept JSON and my client is going to be in Java. It is actually going to be part of an existing enterprise EJB project.

我已經(jīng)編寫(xiě)了一個(gè)客戶端并且能夠成功調(diào)用 RESTful 服務(wù).事實(shí)上,如果我以字符串(JSON 格式)發(fā)送請(qǐng)求,我什至?xí)盏交貜?fù).但我想避免這種將 Map 轉(zhuǎn)換為 JSON 格式字符串然后在 Request 中發(fā)送出去的手動(dòng)工作.

I have written up a client and am able to call the RESTful service successfully. In fact, if I send the request in String (JSON format) then I even get a response back. But I would like to avoid this manual work of converting the Map into a JSON format string and then sending it out in Request.

我已將 Content-Type 設(shè)置為 application/json 并創(chuàng)建了一個(gè)包含 KeyValue 對(duì)的 Map.

I have set Content-Type as application/json and have created a Map which will contain the KeyValue pair.

來(lái)自客戶端的代碼片段:

Snippet of code from Client:

HttpHeaders headers = new HttpHeaders();

headers.setContentType(MediaType.APPLICATION_JSON);
headers.add(MyConstants.JWT_AUTH_TOK, restUtil.getJWTToken());

restTemplate = new RestTemplate();

ModelReqVO modVO = new ModelReqVO();
Map<String, String> dataMap = new HashMap<String, String>();
//Setting key,value into datamap (e.g. "key1", "value1")
modVO.setDataMap(dataMap);

ResponseEntity<ModelRspnsVO> result = restTemplate.postForEntity(mySrvcFN, new HttpEntity(modVO, headers), ModelRspnsVO.class);

請(qǐng)求(ModelReqVO)類:

Request (ModelReqVO) Class:

public class ModelReqVO {

private HashMap<String, String> dataMap;

ModelReqVO() {
    this.dataMap = new HashMap<String, String>();
}

//getter and setter generated
}

這是我得到的例外-

RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.mycomp.myproj.ModelReqVO] and content type [application/json].

我檢查了我的 restTemplate 上的 HttpMessageConverters,我確實(shí)找到了 MappingJacksonHttpMessageConverter.代碼中還需要我使用上述轉(zhuǎn)換器嗎?

I checked the HttpMessageConverters that I have on my restTemplate and I did find MappingJacksonHttpMessageConverter. Is something else required of me in the code to use the said converter?

我在 Spring.io 論壇上找到了幾個(gè)示例,但它們是關(guān)于需要 www/form 內(nèi)容而不是 JSON 的服務(wù).令人驚訝的是,我沒(méi)有找到有關(guān)使用特定轉(zhuǎn)換器將 Map 作為 JSON 發(fā)送的任何詳細(xì)信息.

I found a couple of examples on Spring.io forums, but they were about a service which required www/form content and not JSON. I, surprisingly, do not find any details about using a particular converter for Map to be sent as a JSON.

注意:代碼片段可能有編譯錯(cuò)誤,我是從手機(jī)上輸入代碼的.出于安全原因,我無(wú)法在我編碼的機(jī)器上使用互聯(lián)網(wǎng).

Note: The code snippets might have compile errors, I have typed the code out from my mobile. I cannot use the internet on the machine that I code in for security reasons.

推薦答案

報(bào)錯(cuò)信息說(shuō)沒(méi)有找到適合請(qǐng)求類型的HttpMessageConverter,所以只需在MappingJackson2HttpMessageConverter>MediaType 到 RestTemplate

The error message says no suitable HttpMessageConverter found for request type, so just add MappingJackson2HttpMessageConverter with MediaType to RestTemplate

MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); 
coverter.setSupportedMediaTypes(Arrays.asList(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON); 
restTemplate.getMessageConverters().add(0, converter)

這篇關(guān)于HttpMessageConverter 異常:RestClientException:無(wú)法寫(xiě)入請(qǐng)求:找不到合適的 HttpMessageConverter的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉(zhuǎn)換為 Map)
Getting data from JSON(從 JSON 獲取數(shù)據(jù))
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對(duì)象列表轉(zhuǎn)換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個(gè)固定的Key對(duì)應(yīng)一個(gè)HashSet創(chuàng)建一個(gè)HashMap.出發(fā)點(diǎn))
Best way to order an HashMap by key in Java?(在 Java 中按鍵排序 HashMap 的最佳方法?)
主站蜘蛛池模板: 国产网站视频 | 国产在线黄色 | 亚洲第一免费视频 | 中文字幕一区二区三区视频 | 美女综合网| 欧美激情综合五月色丁香 | 亚洲精品视频在线观看免费 | 欧美日韩精品久久久免费观看 | av免费观看网站 | 黄色三级在线观看 | 日本天堂在线观看 | 91久久国产综合久久91精品网站 | 成人免费公开视频 | 谁有毛片网站 | 亚洲久久在线 | 偷拍一区二区三区 | 日韩一区二区中文字幕 | 思思在线视频 | 91性高潮久久久久久久久 | 人人超碰在线 | 免费av不卡 | 秋霞福利视频 | 欧美一级片免费看 | 一区二区三区高清 | 午夜在线影院 | 97精品在线 | 欧美日韩一区二区三区视频 | 超碰777| 国产成人精品久久久 | 亚洲成人中文字幕 | 欧美日韩在线一区 | 国产成人精品一区二区三区福利 | 国产永久在线 | 国产亚洲久一区二区 | 亚洲一区二区 | 亚洲综合在线视频 | 六月色婷婷 | 特级黄色大片 | 91精品久久久久久久久 | www.国产一区 | 天天干天天色天天射 |