Provide a way to send a JSON object with WebClient
Motivation: It would also be nice to have APIs that automatically convert a request body into bytestring and converts a response into an object.
Modifications:
- Add method
ofJsoninHttpRequest - Add method
aggregateAsinHttpResponse
Result:
- Closes #3707
- Users can convert a request body into bytestring automatically :
HttpRequest.ofJson(HttpMethod.POST, "/receiveContent", requestContent)
- Users can convert a response into an object automatically :
Content content = HttpResponse.of(MediaType.JSON_UTF_8, contentString)
.aggregateAs(Content.class)
.join();
ErrorMessage error = HttpResponse.of(MediaType.JSON_UTF_8, contentString)
.aggregateAs(HttpStatusClass.SERVER_ERROR, ErrorMessage.class)
.join();
ErrorMessage error = HttpResponse.of(MediaType.JSON_UTF_8, contentString)
.aggregateAs(status -> status != HttpStatus.OK, ErrorMessage.class)
.join();
Wrapper<Content> wrapperContent = HttpResponse.of(MediaType.JSON_UTF_8, contentString)
.aggregateAs(new TypeReference<Wrapper<Content>>(){})
.join();
Codecov Report
Attention: Patch coverage is 35.38462% with 42 lines in your changes missing coverage. Please review.
Project coverage is 73.16%. Comparing base (
829992a) to head (9a74a7b). Report is 1036 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #3757 +/- ##
============================================
- Coverage 73.18% 73.16% -0.03%
- Complexity 16126 16133 +7
============================================
Files 1405 1408 +3
Lines 61669 61734 +65
Branches 7765 7771 +6
============================================
+ Hits 45134 45165 +31
- Misses 12612 12631 +19
- Partials 3923 3938 +15
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@karellen-kim I think #4021 takes over the features of this PR. Let me close this PR. 🙇♂️ I hope to see the next PR in the near future. 😆
But still we can't send a JSON object as it is, right? #4021 only takes care of the receiving part.
Ah, this PR includes HttpRequest.ofJson() also. I missed that. Let me reopen and continue to develop the sending part.
Gentle ping. @karellen-kim