-
Notifications
You must be signed in to change notification settings - Fork 795
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
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
|
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
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
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
@RequestPart
s, but it was only forMultipartFile
and boxed primitive types. This PR builds on the abovementioned PR by:SpringEncoder
to (optionally) use a newSpringPojoFormEncoder
that comes with aPojoFormWriter
, which serializes user-defined POJOs.PojoFormWriter
is abstract; developers can implement missing methods to serialize POJOs to any string format. In this PR, I implementedJsonPojoFormWriter
, which uses Jackson.FeignClientsConfiguration
to optionally autowire aPojoFormWriter
that will be used withSpringEncoder
upon application start-up.SpringMvcContract.processAnnotationsOnParameter
to not expand parameters when theContent-Type
ismultipart/form-data
. This is because a simple, single-field POJO likeFeignClientTests.Hello
would have been converted to aString
.I am not sure how best to fix the issue in
processAnnotationsOnParameter
and 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 becauseSpringEncoder
itself has an internal instance ofSpringFormEncoder
, I thought it would be cleaner to make a PR here.