Hi,
I wasn't aware that Optional actually isn't serializable:
https://stackoverflow.com/questions/24547673/why-java-util-optional-is-not-serializable-how-to-serialize-the-object-with-suc#24564612
"The JSR-335 EG felt fairly strongly that Optional should not be on any
more than needed to support the optional-return idiom only. (Someone
suggested maybe even renaming it to OptionalReturn to beat users over
the head with this design orientation; perhaps we should have taken that
suggestion.)"
(I wonder whether we follow this usage guideline everywhere.)
So it seems an optional @Inject is not possible with our usecase.
I'm +0 on changing anything here, although @Autowired would be fine too.
Regards
Sven
On 02.06.21 10:09, Martin Grigorov wrote:
Hi,
In my email about ideas what to do for Wicket 10 (
https://markmail.org/message/vpptsmt4ysxbktzc) I have suggested to
drop @SpringBean and use jakarta.inject.Inject/Named instead.
While working on it I've faced one issue - there is no support for
non-required bean:
@SpringBean(required = false)
private SomeBean someBean;
If there is no matching bean in the Spring application context then nothing
will be injected. Without 'required = false' the instantiation of the
Component will fail with an Exception.
With jakarta.inject APIs there is no way to say that something is optional.
I've tried by using java.util.Optional:
@Inject
private Optional<SomeBean> someBean;
but the problem here is that j.u.Optional is a final class and cannot be
enhanced by CGLib to create a serializable proxy around it.
Another option is to create a custom annotation, e.g. @Optional in
wicket-ioc.
Do you have other ideas ?
Or should we stay with @SpringBean or even use Spring's @Autowired ?!
Martin