Jayesh Choudhary
Jayesh Choudhary

Reputation: 798

Feign Client: DecodeException: Error while extracting response

I am using Open Feign and Hateos in my Microservice Architecture. When I am fetching content using Feign clientI get following error:

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"])

Below is my feign client:

@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();

}

Below I am providing Feign client configuration:

@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();
    }

Can anyone tell me where I am making mistake or what else I need to configure to achieve this ?

Upvotes: 4

Views: 19861

Answers (1)

Jayesh Choudhary
Jayesh Choudhary

Reputation: 798

Sorry for posting this answer late. After Juggling around I find out that feign client was working completely fine. The main problem was in parsing the JSON object which was received. As I checked log in detail.

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

It contained one time entity which Jackson was unable to parse so I used the following piece of code in my document class.

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

That solved my problem. Hope it helps anyone else as well...!

Upvotes: 4

Related Questions