4

I have a feign client that uses a dto to perform the request using @RequestBody. The problem is that some property does not match with the java standards, for example id_client. Is there a way to change the variable name and keep it working with the feign ?

Below there is the code of the feign client the dto used in the request body.

@FeignClient(name="sso-token", url = "http://keycloak.com.br:8180", path="/")
public interface SsoTokenQueryWebAdapter {


    @PostMapping(value = "/auth/realms/real-refrigerantes/protocol/openid-connect/token", consumes = "application/x-www-form-urlencoded")
    public String recuperarToken(@RequestBody RequestTokenDto dto);

}

@Data
public class RequestTokenDto {
    
private String username;

    private String password;

    private String client_id;

    private String client_secret;
    
    private String grant_type;

}
  • 1
    maybe this can answer your question https://stackoverflow.com/questions/69682344/how-do-i-parse-snake-case-fields-in-a-feignclient-response-json – Hải Trịnh Duy Feb 24 '22 at 02:32
  • 1
    Jackson is used under the hood, so any solution that works for Jackson, in general, should work here. You could try using `@JsonAlias()`. – OlgaMaciaszek Feb 25 '22 at 14:45

1 Answers1

0
@Data
public class RequestTokenDto {
    private String username;
    private String password;

    @FormProperty("client_id")
    @JsonProperty("client_id")
    private String clientId;

    @FormProperty("client_secret")
    @JsonProperty("client_secret")
    private String clientSecret;

    @FormProperty("grant_type")
    @JsonProperty("grant_type")
    private String grantType;
}