Some decoders support decoding a proper payload from empty DataBuffers. One good example is the ProtobufDecoder.
This patch adds a method canDecodeEmptyDataBuffer() to the Decoder interface, allowing the Decoder to signal that it is able to do that.
In this case, the PayloadMethodArgumentResolver should pass the empty DataBuffer to the Decoder, and in all other cases behave like before.
Comment From: spheenik
In response to the following issue: https://github.com/spring-projects/spring-framework/issues/29898
Comment From: spheenik
I updated the remaining Decoders that are capable to decode empty buffers to also return true
on canDecodeEmptyDataBuffers()
.
I also added tests for the decode()
and the decodeToMono()
scenarios, and made sure all the marked Decoders support it properly.
Comment From: spheenik
Thank you for the detailed explanation of the toMono-Case, and your other remarks. Seems I definitively had a misunderstanding what it is used for.
As a consequence, I renamed the method to canDecodeEmptyMessage
, as suggested. I also improved on it's documentation, stating that, if the decoder returns true here, the contract will be that it will never return null when decoding an empty Message. I did not mention the error case though, which of course can happen.
I was wondering whether or not to leave the test in the toMono case in, and decided to do so, and improved on it by giving it a Flux of two empty DataBuffers as an input, to make sure a supporting decoder gives only one non-null result back.
Comment From: spheenik
@simonbasle I was also thinking about this, and I can certainly see why you are worried. I came to the conclusion that as long as the decoder makes sure to always return something non null, it should be fine. All the decode- and decodeToMono-Scenarios of the ByteArray-style decoders act in this way anyway, not even looking at the flag.
For the StringDecoder
, it even includes a proper fix, instead of the workaround in gh-26344.
Of course, this is only with my limited knowledge, so I am eagerly awaiting @rstoyanchev 's insight.
Comment From: spheenik
I just rechecked, the only place in the whole framework code where canDecodeEmptyMessage()
is even used is in the PayloadMethodArgumentResolver
in spring-messaging
. Everything else is acting like before.
Comment From: spheenik
It's been a while, nothing happened. To make sure, this doesn't get lost, question: Is there anything more I can do?
Comment From: snicoll
@spheenik thank you for following up. We need to take the time to review it one more time to answer your questions.