假装客户端: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
无法解析的时间实体,所以我在我的文档 class.
中使用了以下一段代码
@JsonSerialize(using = LocalTimeSerializer.class)
@JsonDeserialize(using = LocalTimeDeserializer.class)
private LocalTime sendOn;
这解决了我的问题。希望它也能帮助其他人...!
我在我的微服务架构中使用 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
无法解析的时间实体,所以我在我的文档 class.
@JsonSerialize(using = LocalTimeSerializer.class)
@JsonDeserialize(using = LocalTimeDeserializer.class)
private LocalTime sendOn;
这解决了我的问题。希望它也能帮助其他人...!