Skip to content

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

Merged
velo merged 7 commits into
OpenFeign:masterfrom
EduardoRadieske:fix/map-string-urlencoded
Oct 5, 2026
Merged

velo merged 7 commits into
OpenFeign:masterfrom
EduardoRadieske:fix/map-string-urlencoded

Conversation

@EduardoRadieske

@EduardoRadieske EduardoRadieske commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix form encoding so JDK types are no longer treated as POJOs.

Changes

  • Treat primitives, arrays and java.* types, including parameterized ones like Map<String, String> and List<String>, as non-POJOs. PojoUtil.isUserPojo(Type) now resolves the raw type with feign.Types.getRawType.
  • Non-Map JDK types, such as a List<String> body, go to the default encoder instead of failing on reflective field access.
  • SpringContract had its own copy of the old "class java." check. A @RequestHeader of type List<String>, int or byte[] was treated as a header map. It now uses the same rule.
  • Add tests covering Map, collection, primitive, array, POJO and parameterized type handling, plus a SpringContract test for JDK-typed headers.

Testing

Unit and end-to-end tests in form and spring.

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
Contributor 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.

…ingContract header POJO check

Signed-off-by: Marvin Froeder <velo.br@gmail.com>

@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 working through the review! I pushed a follow-up commit: isUserPojo(Type) now uses feign.Types.getRawType, which also fixes default-package classes on Java 8. The WildCardMapTest logger setup is back to match the sibling tests; if Windows cleanup is a problem, let's fix all five tests in a separate PR. The generic type parameter moved into its own GenericPojo fixture, and a few test names were renamed. SpringContract had the same "class java." check, so I fixed it there too and added a test. I also updated the description.

@velo
velo enabled auto-merge October 5, 2026 11:37
@velo
velo merged commit 8ff6e3d into OpenFeign:master Oct 5, 2026
3 checks passed
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