【问题标题】:Getting no suitable HttpMessageConverter found for response type找不到适合响应类型的 HttpMessageConverter
【发布时间】:2020-12-09 17:52:32
【问题描述】:

org.springframework.web.client.UnknownContentTypeException:无法提取响应:没有找到适合响应类型 [class net.minidev.json.JSONObject] 和内容类型 [application/json] 的 HttpMessageConverter

public String handleRequest(ScheduledEvent event, Context context) {
    LambdaLogger logger = context.getLogger();
    String requestBody = System.getenv().get("REQUEST_BODY");
    String endpointUrl = System.getenv().get("ENDPOINT_URL");
    String authorizationHeader = System.getenv().get("AUTHORIZATION_HEADER");
    ResponseEntity<JSONObject> response = restTemplate.getForEntity(endpointUrl, JSONObject.class);
    logger.log(response.getBody().getAsString("Total document signed"));
    String lambdaResponse = new String("200 OK");
    return lambdaResponse;
}

endpointUrl 也返回 JSONObject,所以不知道为什么不匹配

【问题讨论】:

    标签: spring spring-resttemplate


    【解决方案1】:

    resttemplate 转换器不直接转换为 JSONObject。

    您可以更改它,以便 restTemplate 将响应作为字符串提供,然后可以将其转换为 JSONObject。

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 2016-05-15
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      相关资源
      最近更新 更多