You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Optional in PayloadMethodArgumentResolver #28945
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).
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.
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.
changed the title [-]Improve org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver for better end-user experience[/-][+]Improve `PayloadMethodArgumentResolver` for better end-user experience[/+]on Jan 30, 2023
changed the title [-]Improve `PayloadMethodArgumentResolver` for better end-user experience[/-][+]Support `Optional` in `PayloadMethodArgumentResolver`[/+]on Feb 7, 2023
Activity
rstoyanchev commentedon Jan 24, 2023
I think you're suggesting to turn
Optionalintonullif the method parameter is notOptional, and is not required. I think we could do that. Wouldn't we want the opposite too, i.e. wrap withOptionalif the method parameter isOptional?As for
@Nullable @Payload payloadthis has to be decided more broadly for such annotated handler methods, including web where we also don't support that currently.artembilan commentedon Jan 24, 2023
Hi @rstoyanchev !
Right, I concur with all your arguments.
Plus we'd like to have that check for
Optional.isEmpty()in theisEmptyPayload(). In Spring Integration we are going to implement aNull 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 payloadin the separate issue.rstoyanchev commentedon Jan 30, 2023
I've scheduled it for the
Optionalsupport improvements but I'll discuss the@Nullableand provide and update or create another issue if necessary.[-]Improve org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver for better end-user experience[/-][+]Improve `PayloadMethodArgumentResolver` for better end-user experience[/+][-]Improve `PayloadMethodArgumentResolver` for better end-user experience[/-][+]Support `Optional` in `PayloadMethodArgumentResolver`[/+]Polishing
PayloadMethodArgumentResolver supports Optional