It will be very useful to be able to save values ​​to current session based on annotations, for example:

   @SaveSession(attributeName = "hello")
    public String getValue() {
        return "Hello world";
    }

Comment From: marcusdacoregio

Hi, @CrazyParanoid. Can you elaborate more on the benefits of this feature? At first, I don't see a fit for such annotation in the framework since the equivalent code would be just session.setAttribute("hello", "Hello world").

Comment From: franticticktick

Hi @marcusdacoregio! For example, I have an otp generation service, I want to generate an otp, send it to the user and save it in the session:

fun generateOtp(request: SendOtpRequest, exchange: ServerWebExchange) =
        Mono.just(request.toOtp())
            .flatMap { otp ->
                exchange.session
                    .flatMap {
                        it.attributes[OTP] = otp
                        Mono.just(otp)
                    }
            }
            .publishOn(Schedulers.boundedElastic())
            .flatMap { otpAdapter.sendOtpToUser(it) }
            .doOnSuccess { log.info("OTP has been sent") }
            .then()

My code could be much cleaner and simpler:

   @SaveSession(attributeName = "otp")
    fun generateOtp(request: SendOtpRequest) =
        Mono.just(request.toOtp())
            .publishOn(Schedulers.boundedElastic())
            .flatMap { otpAdapter.sendOtpToUser(it) }
            .doOnSuccess { log.info("OTP has been sent") }

Accordingly, unit tests will become simpler and unnecessary mocks will be avoided. This is a real example.

Comment From: marcusdacoregio

Thanks @CrazyParanoid. However, I still don't see the value of such support in the framework. It feels like this annotation is not a cross-cutting concern to your application, its usage is related to some business need and at first it feels that it should stay near the business code.

I'll close this for now if that's ok for you, but we can always re-evaluate if we get enough comments of users wanting to achieve the same behavior.