OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.5k stars 1.93k forks source link

Is not record class supported when using `@SpringQueryMap`? #1927

Open DaehunGwak opened 1 year ago

DaehunGwak commented 1 year ago

Hello. When the @SpringQueryMap parameter is apllied as record class, http query is not recognized. Is there some plan or has it already been updated?

using feign version

test result

summary

test type

test report

record class

record class

public record PostQueryRecord(Long postId) {
}

feign method

@GetMapping("/comments")
void getCommentsRecord(@SpringQueryMap PostQueryRecord query);

result: query parameter is not recognized

[TestFeingClient#getCommentsRecord] ---> GET https://jsonplaceholder.typicode.com/comments HTTP/1.1

record class + adding get accessor

record class + get accessor

public record PostQueryRecordGetter(Long postId) {
    public Long getPostId() {
        return postId;
    }
}

feign method

@GetMapping("/comments")
void getCommentsRecordGetter(@SpringQueryMap PostQueryRecordGetter query);

result: query parameter is recognized

[TestFeingClient#getCommentsRecordGetter] ---> GET https://jsonplaceholder.typicode.com/comments?postId=1 HTTP/1.1

normal class + getter accesor

normal class

@Getter
@RequiredArgsConstructor
public class PostQueryClass {
    private final Long postId;
}

feign method

@GetMapping("/comments")
void getCommentsRecord(@SpringQueryMap PostQueryClass query);

result: query parameter is recognized

[TestFeingClient#getCommentsRecord] ---> GET https://jsonplaceholder.typicode.com/comments?postId=1 HTTP/1.1
vitorpavanelli commented 1 year ago

I have the same issue. It seems it have stopped working.

andreaippo commented 1 year ago

I have the same issue and for me it started happening since adding the dependency to redis:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

I am using a record where the param names are multi-word, so that I have to use the feign.Param annotation to specify the name I want for the resulting queryParam:

public record MyRecord(

@Param(value = "my_param_1") String param1,

@Param(value = "my_param_2") boolean param1

) {

Then I use this like this:

MyFeignClient {

myFeignMethod(@SpringQueryMap MyRecord myRecord);

}

And this worked fine until I added the dependency to redis, as I said.

Any help appreciated.

Using spring-cloud-openfeign-core:4.0.0 + spring-data-redis:3.0.1

kdavisk6 commented 1 year ago

This is more than likely an incompatibility introduced for later JDK support. Since you are using SpringQueryMap to expand the parameter, I recommend opening an issue with Spring Cloud OpenFeign, since it is there where the problem may lie, not in Feign.