Custom encoders and decoders
The Feign Builder API allows us to create custom encoders for a request, and decoders for a response, to the Feign client.
Custom encoder
Let's create a custom encoder for a request body.
The request body data has been sent to the server by a POST
method using either the String
or byte[]
parameter. You can add a Content-Type
header:
interface AccountService { @PostMapping("/account/") @Headers("Content-Type: application/json") Account create(@RequestBody Account account); }
Let's configure your own custom encoder; now it will be the type-safe request
body. Let's see the following example using the feign-gson
extension:
class Account { Integer accountId; Double balance; Integer customerId; String accountType; String branchCode; String bank; public Account(Integer accountId, Double balance, Integer customerId, String accountType, String branchCode, String bank) { super(); this.accountId = accountId...