-
Notifications
You must be signed in to change notification settings - Fork 815
Allow @RequestPart user-defined POJOs #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow @RequestPart user-defined POJOs #314
Conversation
03618b5 to
75066f9
Compare
Codecov Report
@@ Coverage Diff @@
## 2.2.x #314 +/- ##
============================================
+ Coverage 78.84% 79.01% +0.17%
- Complexity 396 411 +15
============================================
Files 52 54 +2
Lines 1541 1587 +46
Branches 223 230 +7
============================================
+ Hits 1215 1254 +39
- Misses 233 237 +4
- Partials 93 96 +3
|
spencergibb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll let @OlgaMaciaszek comment on actual functionality as opposed to just structure and naming.
...-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java
Outdated
Show resolved
Hide resolved
...openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PojoFormWriter.java
Outdated
Show resolved
Hide resolved
...openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PojoFormWriter.java
Outdated
Show resolved
Hide resolved
...gn-core/src/main/java/org/springframework/cloud/openfeign/support/SpringPojoFormEncoder.java
Outdated
Show resolved
Hide resolved
…FeignClientsConfiguration
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@darrenfoong Thanks for submitting this. The logic looks good to me, but I've added some comments for you to address.
...nfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java
Outdated
Show resolved
Hide resolved
...nfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java
Outdated
Show resolved
Hide resolved
...-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java
Outdated
Show resolved
Hide resolved
...-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java
Show resolved
Hide resolved
...feign-core/src/main/java/org/springframework/cloud/openfeign/support/AbstractFormWriter.java
Show resolved
Hide resolved
...nfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java
Outdated
Show resolved
Hide resolved
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks @spencergibb and @OlgaMaciaszek for reviewing and merging this PR! |
I'm using Spring Cloud OpenFeign, and I have a use case where I need to send multiple files and user-defined POJOs as
multipart/form-data, for example:There was a recent fix in #258 that allowed the use of multiple
@RequestParts, but it was only forMultipartFileand boxed primitive types. This PR builds on the abovementioned PR by:SpringEncoderto (optionally) use a newSpringPojoFormEncoderthat comes with aPojoFormWriter, which serializes user-defined POJOs.PojoFormWriteris abstract; developers can implement missing methods to serialize POJOs to any string format. In this PR, I implementedJsonPojoFormWriter, which uses Jackson.FeignClientsConfigurationto optionally autowire aPojoFormWriterthat will be used withSpringEncoderupon application start-up.SpringMvcContract.processAnnotationsOnParameterto not expand parameters when theContent-Typeismultipart/form-data. This is because a simple, single-field POJO likeFeignClientTests.Hellowould have been converted to aString.I am not sure how best to fix the issue in
processAnnotationsOnParameterand I don't have a good understand of what it does exactly. I'd like to know a better way to prevent expansion of simple POJOs likeFeignClientTests.Hello.I had earlier created a pull request on feign-form (OpenFeign/feign-form#89), but considering that the project is not regularly maintained, I decided to make a PR here instead.
I had also noticed that the recommended usage on feign-form's documentation is to create a
new SpringFormEncoder(new SpringEncoder(...)), but becauseSpringEncoderitself has an internal instance ofSpringFormEncoder, I thought it would be cleaner to make a PR here.