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) ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.