@SpringQueryMap not working with Java Record
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.
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
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
FieldQueryMapEncoderfield for Record encoding - Add
isRecord()check betweensupports()andsuper.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)
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.
Thank you sir