Repository navigation
fix(form): correctly handle Map and POJO types - #3586
Conversation
- improve POJO detection for parameterized types - prevent Map and collection types from being treated as POJOs - add PojoUtil unit tests - update WildCardMapTest
f8c5848 to
89648ae
Compare
velo
left a comment
There was a problem hiding this comment.
Thanks for the fix. A couple of things before this can go in:
Blocking
PojoUtil.isUserPojo(Class)callstype.getPackage().getName(), butgetPackage()returnsnullfor arrays and primitives. A form-encoded method with abyte[]orintbody now throws an NPE inFormEncoder.encode. WithcreatePredicatedFormEncoder()the predicate throws instead of returningfalse, so the request never reaches the delegate encoder. Please returnfalsefor primitives, arrays, and classes with no package, and add a test for each.WildCardMapTest.testMapStringStringalready passes on master, becauseFormEncoder.encodeand theformRequestspredicate checkinstanceof Mapbefore callingisUserPojo. So it doesn't cover the fix. The real improvement is non-Map JDK types (e.g. aList<String>body or a raw interface type) no longer being treated as POJOs. Please add an end-to-end test throughFormEncoderfor that case.
Nits
FormEncoder.isMap(Object)only wrapsinstanceof Map; inline it.- Please revert the unrelated changes: the javadoc
<pre>reformat, and theappendToFileremoval, which leaves the@TempDir logDirfield unused. - The test package is
feign.form.utils, but the main package isfeign.form.util. PojoUtilTest.TypeReferencewritesjava.lang.reflect.ParameterizedTypein full even though it's already imported.
|
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
left a comment
There was a problem hiding this comment.
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.
Description
Fix form encoding so JDK types are no longer treated as POJOs.
Changes
java.*types, including parameterized ones likeMap<String, String>andList<String>, as non-POJOs.PojoUtil.isUserPojo(Type)now resolves the raw type withfeign.Types.getRawType.List<String>body, go to the default encoder instead of failing on reflective field access.SpringContracthad its own copy of the old"class java."check. A@RequestHeaderof typeList<String>,intorbyte[]was treated as a header map. It now uses the same rule.Map, collection, primitive, array, POJO and parameterized type handling, plus aSpringContracttest for JDK-typed headers.Testing
Unit and end-to-end tests in
formandspring.Related issue: #2827