Sometime the data for payload method argument is optional and we cover that with a @Payload(required = false)
.
It would be nice if this PayloadMethodArgumentResolver
would treat a @Nullable payload
same way as that required = false
.
Another improvement is around an Optional
: the isEmptyPayload(@Nullable Object payload)
should add a check for Optional.isEmpty()
.
Technically we cannot transfer a null
in messaging at the moment, so the Optional.empty()
is good compromise for us.
However this one probably should have an effect only if method param type is not an Optional
, so no checks no conversions necessary. I assume this is an existing behavior.
What we need is just an automatic Optional
resolution to null
if @Nullable
or @Payload(required = false)
.
Thanks
Comment From: rstoyanchev
I think you're suggesting to turn Optional
into null
if the method parameter is not Optional
, and is not required. I think we could do that. Wouldn't we want the opposite too, i.e. wrap with Optional
if the method parameter is Optional
?
As for @Nullable @Payload payload
this has to be decided more broadly for such annotated handler methods, including web where we also don't support that currently.
Comment From: artembilan
Hi @rstoyanchev !
Right, I concur with all your arguments.
Plus we'd like to have that check for Optional.isEmpty()
in the isEmptyPayload()
. In Spring Integration we are going to implement a Null payload feature
: some users are requesting to be able to produce nulls from their POJO methods as valid result for a reply message.
Yes, we can revise @Nullable payload
in the separate issue.
Comment From: rstoyanchev
I've scheduled it for the Optional
support improvements but I'll discuss the @Nullable
and provide and update or create another issue if necessary.