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

@SpringQueryMap not working with Java Record

Open marcusvoltolim opened this issue 3 months ago • 3 comments

Describe the bug The problem is with @SpringQueryMap because it uses PageableSpringQueryMapEncoder which extends BeanQueryMapEncoder, limiting it to just these two encoders.

In feign.QueryMap, you can define mapEncoder as either BEAN or FIELD.

Image

Solution: Defines the Bean:

   @Bean
    public QueryMapEncoder feignQueryMapEncoderPageable() {
        return new FieldQueryMapEncoder();
    }

However, it is incompatible with Pageable throwing exception:

Request processing failed: java.lang.IllegalStateException: Duplicate key serialVersionUID (attempted merging values -4541509938956089562 and 1232825578694716871)] with root cause

marcusvoltolim avatar Oct 08 '25 20:10 marcusvoltolim

Hi, I'm interested in contributing a fix for this issue.

I've analyzed the codebase and prepared two different approaches as Draft PRs:


Option A: Modify PageableSpringQueryMapEncoder directly

PR: #Add Record support in PageableSpringQueryMapEncoder

Add Record detection in the existing encode() method:

  • Add FieldQueryMapEncoder field for Record encoding
  • Add isRecord() check between supports() and super.encode()
// Simplified change
if (object.getClass().isRecord()) {
    return recordEncoder.encode(object);
}
return super.encode(object);
Pros Cons
Minimal change (1 file) Pageable encoder handles Record logic (SRP concern)
No new classes

Option B: Create new RecordQueryMapEncoder class

PR: #Add RecordQueryMapEncoder for @SpringQueryMap Record support

Create a new encoder class and modify inheritance:

  • NEW: RecordQueryMapEncoder - Routes Record → FieldQueryMapEncoder, POJO → BeanQueryMapEncoder
  • MODIFIED: PageableSpringQueryMapEncoder extends RecordQueryMapEncoder (1 line change)

brightJoo avatar Nov 30 '25 07:11 brightJoo

I think we would prefer option A because it is backward compatible. We would want that PR submitted against the 4.2.x branch and then we can merge it forward.

ryanjbaxter avatar Dec 02 '25 16:12 ryanjbaxter

Thank you sir

brightJoo avatar Dec 02 '25 22:12 brightJoo