Skip to content

fix(form): correctly handle Map and POJO types - #3586

Open
EduardoRadieske wants to merge 6 commits into
OpenFeign:masterfrom
EduardoRadieske:fix/map-string-urlencoded
Open

EduardoRadieske wants to merge 6 commits into
OpenFeign:masterfrom
EduardoRadieske:fix/map-string-urlencoded

Conversation

@EduardoRadieske

@EduardoRadieske EduardoRadieske commented Sep 27, 2026 •

Copy link
Copy Markdown

Description

Fix form encoding for Map and POJO types by improving type detection.

Changes

  • Improve POJO detection for parameterized types.
  • Prevent Map, collection, primitive, and array types from being treated as POJOs.
  • Ensure non-Map JDK types are delegated to the default encoder.
  • Add and update tests covering Map, collection, primitive, array, POJO, and parameterized type handling.

Testing

Added and updated unit and end-to-end tests covering the affected form encoding paths.

Related issue: #2827

- improve POJO detection for parameterized types

- prevent Map and collection types from being treated as POJOs

- add PojoUtil unit tests

- update WildCardMapTest
@EduardoRadieske
EduardoRadieske force-pushed the fix/map-string-urlencoded branch from f8c5848 to 89648ae Compare September 27, 2026 02:27

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. A couple of things before this can go in:

Blocking

  1. PojoUtil.isUserPojo(Class) calls type.getPackage().getName(), but getPackage() returns null for arrays and primitives. A form-encoded method with a byte[] or int body now throws an NPE in FormEncoder.encode. With createPredicatedFormEncoder() the predicate throws instead of returning false, so the request never reaches the delegate encoder. Please return false for primitives, arrays, and classes with no package, and add a test for each.
  2. WildCardMapTest.testMapStringString already passes on master, because FormEncoder.encode and the formRequests predicate check instanceof Map before calling isUserPojo. So it doesn't cover the fix. The real improvement is non-Map JDK types (e.g. a List<String> body or a raw interface type) no longer being treated as POJOs. Please add an end-to-end test through FormEncoder for that case.

Nits

  • FormEncoder.isMap(Object) only wraps instanceof Map; inline it.
  • Please revert the unrelated changes: the javadoc <pre> reformat, and the appendToFile removal, which leaves the @TempDir logDir field unused.
  • The test package is feign.form.utils, but the main package is feign.form.util.
  • PojoUtilTest.TypeReference writes java.lang.reflect.ParameterizedType in full even though it's already imported.

@EduardoRadieske

Copy link
Copy Markdown
Author

Thanks for the review. Addressed the requested changes and updated the tests.

I kept appendToFile removed because it causes TempDir cleanup failures on Windows: log.txt remains open when JUnit tries to delete the temporary directory. Since logDir is no longer used, I also removed the unused TempDir field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants