1

I am new to feign. I have a feign client for a token end point. Apparently we are hitting the /token end point to get the a json string {"token" : "xxxxyyyxxx", "scope": "EPServices","expires-in": "3600"}. I have a pojo class to map these attributes.I want to use feign decoder to do that. How do I do that. The return type of my feign client method is String.

Rini
  • 21
  • 5
  • Take a look at this example: [How to use OpenFeign to get a pojo array?](https://stackoverflow.com/questions/55012543/how-to-use-openfeign-to-get-a-pojo-array/55033529#55033529) – Michał Ziober Jun 22 '20 at 21:34

1 Answers1

0

If you already have a pojo class eg. TokenResponse then you directly use it on the feign interface and it will automatically be deserialized into the POJO for you, since Feign has internal decoders to do that for you automatically.

@FeignClient()
public interface TokenClient {
    @GetMapping(path = "/token")
    TokenResponse getToken();
}

After you get a TokenResponse you can use a Jackson object mapper or GsonDecoder to convert it to json string if you'd like in another class.

But if you want this all done automatically simply change to this

@FeignClient()
public interface TokenClient {
    @GetMapping(path = "/token")
    String getToken();
}

and it will be deserialized for you as a json in String.

neshant sharma
  • 174
  • 2
  • 4