Feign client: final fields of payload object are not serialized when executing POST form-urlencoded

31 views Asked by At

In my code I have simple Feign client:

@FeignClient(name = "client", url = "${spring.microservice.tenant-auth.host}")
public interface PerTenantTokenClient {

  @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
  ResponseEntity<AuthenticationResponse> getAuthToken(AuthFormData formData);

}

aimed to execute the following request:

POST https://myhost.net/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type = client_credentials &
client_id = id &
client_secret = secret

getAuthToken() method accepts a payload DTO described as:

@RequiredArgsConstructor
public class AuthFormData {
  private final String grant_type;
  private final String client_id;
  private final String client_secret;
}

When I run this code snippet:

AuthFormData authFormData = new AuthFormData("client_credentials", "id", "secret");
var authTokenResponse = client.getAuthToken(authFormData);

it unexpectedly fails with 400:

[400 Bad Request] during [POST] to [https://myhost.net/oauth/token] [PerTenantTokenClient#getAuthToken(AuthFormData)]: [{
  "error" : "invalid_request",
  "error_description" : "Missing parameter: grant_type"
}]

However, if I remove final from AuthFormData fields' declaration the same code succeeds.

I've tried to declare AuthFormData as Java record and it fails either (apparently due to implicit final on record members).

So my question is whether I'm facing a bug in feign client or something is wrong with my code? I use io.github.openfeign:feign-core:13.1 and Java 21

1

There are 1 answers

0
Sergey Tsypanov On