繁体   English   中英

Feign Client:DecodeException:提取响应时出错

[英]Feign Client: DecodeException: Error while extracting response

我在我的微服务架构中使用 Open Feign 和 Hateos。 当我使用 Feign 客户端获取内容时,出现以下错误:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.codec.DecodeException: Error while extracting response for type [java.util.List<com.nyota.nyotaplatform.model.asset.Product>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.time.LocalDateTime` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.time.LocalDateTime` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1582] (through reference chain: java.util.ArrayList[1]->com.nyota.nyotaplatform.model.asset.Product["vendor"]->com.nyota.nyotaplatform.model.asset.Vendor["kyc"]->java.util.ArrayList[0]->com.nyota.nyotaplatform.model.fsp.Kyc["document"]->com.nyota.nyotaplatform.model.fsp.Document["uploadDateTime"])] with root cause

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.time.LocalDateTime` out of START_ARRAY token
 at [Source: (PushbackInputStream); line: 1, column: 1582] (through reference chain: java.util.ArrayList[1]->com.nyota.nyotaplatform.model.asset.Product["vendor"]->com.nyota.nyotaplatform.model.asset.Vendor["kyc"]->java.util.ArrayList[0]->com.nyota.nyotaplatform.model.fsp.Kyc["document"]->com.nyota.nyotaplatform.model.fsp.Document["uploadDateTime"])

以下是我的假客户:

@FeignClient(name="asset-market")
public interface AssetMarketClient {

    @RequestMapping(path = "/product/filterProduct", method = RequestMethod.POST)
    Page<Product> getfilterProduct(@RequestBody ProductFilter filter);

    @RequestMapping(path = "/product/getProducts", method = RequestMethod.GET)
    List<Product> getProducts();

}

下面我提供 Feign 客户端配置:

@Bean
    public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
        ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
        resource.setAccessTokenUri(serverUrl);
        resource.setClientId(clientId);
        resource.setClientSecret(secret);
        return resource;
    }

    @Bean
    public RequestInterceptor oauth2FeignRequestInterceptor(){
        return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails());
    }

    @Bean
    public RestTemplate oAuthRestTemplate() {
        DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
        OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(clientCredentialsResourceDetails(), clientContext);
        return restTemplate;
    }

    @Bean
    public RequestContextListener requestContextListener() {
        return new RequestContextListener();
    }

谁能告诉我哪里出错了,或者我还需要配置什么来实现这一目标?

很抱歉发布这个答案晚了。 在玩杂耍之后,我发现feign client工作得很好。 主要问题在于解析收到的 JSON 对象。 当我详细检查日志时。

Cannot deserialize instance of `java.time.LocalDateTime` out of START_ARRAY token

它包含一个Jackson无法解析的实体,所以我在我的文档类中使用了以下一段代码。

@JsonSerialize(using = LocalTimeSerializer.class)
@JsonDeserialize(using = LocalTimeDeserializer.class)
private LocalTime sendOn;

那解决了我的问题。 希望它也能帮助其他人......!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM