简体   繁体   English

POST错误的Java API REST客户端:没有合适的HttpMessageConverter

[英]java api REST client for POST ERROR: no suitable HttpMessageConverter

I use Maven + Spring and I want use RestTemplate().postForEntity(url, request, responseType) + Content-Type=application/json but I have this error: 我使用Maven + Spring,并且我想使用RestTemplate().postForEntity(url, request, responseType) + Content-Type=application/json但是我RestTemplate().postForEntity(url, request, responseType)此错误:

org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [com.kizeoforms.model.User] and content type [application/json] org.springframework.web.client.RestClientException:无法编写请求:找不到适合请求类型[com.kizeoforms.model.User]和内容类型[application / json]的HttpMessageConverter

java REST client code: Java REST客户端代码:

User user = new User();
user.setUser("foo");
user.setPassword("**********");
user.setCompany("xxxxxx");

MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/json");
HttpEntity<User> request = new HttpEntity<User>(user, headers);
ResponseEntity<Object> response = new RestTemplate().postForEntity("https://www.kizeoforms.com:443/rest/v3/login", request, Object.class);
System.out.println(response.getStatusCode());

I had new MappingJackson2HttpMessageConverter() to restTemplate : 我有new MappingJackson2HttpMessageConverter()restTemplate

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<Object> response = restTemplate.postForEntity("https://www.kizeoforms.com:443/rest/v3/login", request, Object.class);

Look into the Restemplate constructor, if there are supported serialized packaged included in your project, the corresponding message converters will be added. 查看Restemplate构造函数,如果项目中包含受支持的序列化打包,则将添加相应的消息转换器。 So you can add a dependency package, such as com.google.gson.Gson or javax.json.bind.Jsonb , then you needn't handle the message converts explicitly. 因此,您可以添加一个依赖包,例如com.google.gson.Gsonjavax.json.bind.Jsonb ,则无需显式处理消息转换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我通过rest模板发布请求时,没有抛出合适的HttpMessageConverter - When I post a request through rest template,It throws no suitable HttpMessageConverter java 中的 HTTP POST 引发错误 - 找不到合适的 HttpMessageConverter 将请求正文读取到 object02ABBBA2F2A298EBDCC4 类型 - HTTP POST in java throws an error - no suitable HttpMessageConverter found to read request body into object of type class 解决“找不到合适的HttpMessageConverter”错误 - Solving "no suitable HttpMessageConverter found" error Spring Rest客户端实现:无法提取响应:没有为xstreamMarshaller找到适合的响应类型的HttpMessageConverter - Spring Rest Client implementation : Could not extract response: no suitable HttpMessageConverter found for response type with xstreamMarshaller RestTemplate Java Spring,没有合适的HttpMessageConverter和422 UnprocessableEntity - RestTemplate Java Spring, no suitable HttpMessageConverter and 422 UnprocessableEntity 休息模板:无法提取响应:当我们得到 xml 响应时,没有找到适合响应类型的 HttpMessageConverter,未绑定到 JAVA 对象 - Rest Template:Could not extract response: no suitable HttpMessageConverter found for response type when we got xml response, not bind to JAVA object 使用 REST 访问 JPA 数据失败找不到合适的 HttpMessageConverter - Accessing JPA Data with REST fails No suitable HttpMessageConverter found Java REST API客户端 - Java REST API CLient Java Android Spring:找不到适合请求类型的HttpMessageConverter - java android spring: no suitable HttpMessageConverter found for request type org.springframework.web.client.RestClientException 中的错误:java.util.HashMap 没有 HttpMessageConverter - Error in org.springframework.web.client.RestClientException: No HttpMessageConverter for java.util.HashMap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM