Allow @RequestPart user-defined POJOs#314
Merged
OlgaMaciaszek merged 28 commits intospring-cloud:2.2.xfrom Apr 14, 2020
Merged
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
requested changes
Apr 8, 2020
Member
spencergibb
left a comment
There was a problem hiding this comment.
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
Collaborator
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
@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
Contributor
Author
|
Thanks @spencergibb and @OlgaMaciaszek for reviewing and merging this PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.