gpt4 book ai didi

java - 假装客户端 : DecodeException: Error while extracting response

转载 作者:行者123 更新时间:2023-12-05 04:05:25 24 4
gpt4 key购买 nike

我在我的微服务架构中使用 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;

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

关于java - 假装客户端 : DecodeException: Error while extracting response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51259956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com