spring-cloud-openfeign icon indicating copy to clipboard operation
spring-cloud-openfeign copied to clipboard

@SpringQueryMap does not honor @Param properties containing dash when spring-boot-starter-data-jdbc is on the classpath

Open jmaniquet opened this issue 1 month ago • 2 comments

Hello there

I recently came upon a strange behavior on the current project I work on.

I want to use a FeignClient to call a search API (GET) with several query parameters. Most of the parameters have a dash in their name, like :

  • dummy-param1
  • dummy-param2

So the GET url is something like : http://localhost:8080/dummyapi?dummy-param1=value1&dummy-param2=value2

Since there are multiple parameters, I want to wrap them in an object and use @SpringQueryMap. I cannot name them with a dash in Java, so i have to map the java properties to the name the API expects with feign @Param annotation :

In my request object :

@Param("dummy-param1")
private String dummyParam1

In my FeignClient interface :

List<DummyResult> findByCriteria(@SpringQueryMap DummyCriteria request);

My feign client is in a dedicated jar with minimal dependencies : lombok, spring-boot-starter-web, spring-cloud-starter-openfeign, spring-boot-starter-test. I also have the habit to write a small integration test with minimal Spring Boot config to easily test my FeignClient. As is, the simple integration test works and I was confident.

However, when integrating my jar in my real application, the real call to the FeignClient does not work as expected : instead of calling the url with the expected params, the url looks likes this : http://localhost:8080/dummyapi?dummyParam1=value1&dummyParam2=value2 They basically become parameters unknown to the API. In my case, the API does not throw any error and just ignore them, and I fetch all the data withouth any filter (fortunately it was paginated).

Since the main difference was a larger Spring context, I immediately suspected that some Spring Boot autoconfiguration was interfering with the request object serialization. Looking into the code of FeignAutoConfiguration, I saw that it had the sub configuration FeignJacksonConfiguration related to Jackson and Spring Data. Since it was related to serialization and since my project uses spring-boot-starter-data-jdbc, this was my first suspect. I tried adding it to my dedicated jar, and my test then started calling the API with the wrong URL.

I used Spring Boot debug mode to look at the autoconfiguration difference between with or without the additional starter. I could only find FeignAutoConfiguration.FeignJacksonConfiguration. I tried disabling it using spring.cloud.openfeign.autoconfiguration.jackson.enabled=false, but it does not seem to work around the problem.

This looks like a bug to me; though I could be wrong and maybe such query params (with the dash) are not supported; and it was by chance that it worked in a smaller setup. I could also be doing something wrong.

My Project uses :

  • Java 21
  • Spring Boot 3.5.11
  • Spring Cloud 2025.0.0 / OpenFeign 4.3.0

I understand that this version of OpenFeign is out of OSS support, so I tried it on :

  • Spring Boot 4.0.9
  • Spring Cloud 2025.1.4 / OpenFeign 5.0.4

The anomaly is still there.

I put up a reproducer : https://github.com/jmaniquet/openfeign-springquerymap-and-springdata-bug The test is green by default. To show the anomaly go to the POM and uncomment the spring-boot-starter-data-jdbc part

Additional consideration

I also suspected lombok; having stumbled upon some shenaningans recently when combined with jackson. That's why my reproducer has two variant : one with lombok @Data, one without and plein old getter/setter. Though they both show the same behaviour, in the non-lombok variant, moving the @Param annotation on the getter actually solves the problem. I guess that it's reflection-related.

I took a look at open issues but did not find anything similar so I opened this ticket. Not sure if it's an OpenFeign thing though. Could be Jackson or Spring Data, so maybe it's the wrong place to start. I'll reopen it elsewhere if appropriate.

Thanks for OpenFeign, its quite cool

jmaniquet avatar Oct 31 '26 14:10 jmaniquet

Hi, I’d be happy to work on this. I can add a regression test for a @SpringQueryMap field annotated with @Param("dummy-param1"), checking the encoded parameter name both with and without Spring Data on the classpath. If the team agrees this should be handled in Spring Cloud OpenFeign, I’d be glad to prepare a fix.

lorentelimaethan avatar Nov 06 '26 15:11 lorentelimaethan

I looked into this and found the root cause: with Spring Data on the classpath, PageableSpringQueryMapEncoder (which extends Feign's BeanQueryMapEncoder) is the default QueryMapEncoder, and BeanQueryMapEncoder only honors @Param on getters. Without Spring Data, SpringFieldQueryMapEncoder is used, and it honors @Param on fields. That's why moving @Param to the getter works around it.

I have a small fix that also honors @Param on the backing field, including inherited fields (a @Param on the getter still takes precedence), with unit tests that check parity with SpringFieldQueryMapEncoder. The full core build passes locally.

@lorentelimaethan, I don't want to step on your toes. Since there's no PR yet, I'm planning to open one, and I'm happy to collaborate or defer if you've already started.

rajeshvasa avatar Nov 15 '26 16:11 rajeshvasa