Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode and Decode ResponseEntity when using Feign and Spring MVC?

I'm trying to use dynamically feign. But i have many issues when converting the response from RequestMapping.

Controller.java :

@RequestMapping("/users")
public ResponseEntity<List<User>> sendUsers

MyFeignClient.java :

public interface MyFeignClient {

@RequestLine(value="GET /api/users")
ResponseEntity<List<User>> getUsers();}

MainClass.java :

MyFeignClient callService = Feign.builder()
            .encoder(new Encoder.Default())
            .decoder(new Decoder.Default())
            .requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
            .target(MyFeignClient.class, "http://localhost:8710");

And then :

ResponseEntity<List<User>> txnPool = callService.getUsers();

But i have the following error :

feign.codec.DecodeException User is not a type supported by this decoder

How can i fix that?

like image 336
3logy Avatar asked Nov 16 '25 19:11

3logy


1 Answers

I resolved it by using JacksonEncoder and JacksonDecoder (from the Netflix Jackson library):

MyFeignClient callService = Feign.builder()
        .encoder(new JacksonEncoder())
        .decoder(new JacksonDecoder())
        .requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
        .target(MyFeignClient.class, "http://localhost:8710");

i also added @Headers("Content-Type: application/json") to my Feign Interface

like image 170
3logy Avatar answered Nov 18 '25 20:11

3logy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!