-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The new Encoder.encodeValue and Decoder.decode methods in spring 5.2 do not provide access to the Context #24441
Comments
This is for custom A custom A custom What do you think? |
Yes, this is for a custom As a temporary workaround (until this issue is addressed), I was thinking about extending I haven't actually looked to see all the places where the new methods are used. If it is limited to
The more I think about it, however, the more I think that having the context as a hint seems hacky. And neither of these implementations handle all the possible locations that the new synchronous methods could be used. So, this would limit any Encoder that uses the context to only be able to be used from the newly patched What if the new synchronous e.g.:
I know this would mean immediately deprecating the newly added synchronous methods, and adding another default reactive method in their place. But, it does seem "cleaner" to have only reactive encode/decode methods in Encoder/Decoder, and to allow implementations to access the context "normally". Also, the default implementation of the new methods might be able to delegate to the other existing methods, rather than throw an exception. (I haven't completely thought that through though) |
At the core, there is a split between use cases with byte streams like HTTP and use cases with discrete messages like RSocket. For the message-oriented use cases, we are always processing discrete payloads that don't need wrapping to begin with but it's the Taking a step back, by comparison it would be quite straight forward to restore the previous behavior of In light of this, I'd like to refine the I do understand this imposes a limitation on the use of reactive context within encoders and decoders but in a messaging scenario this contract is more naturally suited, and when the need arises we'll provide a way to extract and pass additional context much like we pass hints to encoders/decoders today with HTTP. Those hints can come from anywhere, including the Reactor Context. What do you think? |
Ok. That will definitely solve my immediate use case (being able to use the context within encoders used for http) I'm still a little concerned that these encoders will not be able to be used as-is in other places where Also, for future consideration... I would prefer if access to the context was provided to the encoder, rather than having to pluck things out of the context in order to provide them as hints to the encoder. We have various cross-cutting libraries that provide apis for dealing with the context, rather than exposing what they put into the context directly to app code. |
What does this API look like? A representative snippet would suffice, just to get a sense and be able to reason more concretely about it. |
The cross-cutting libraries that work with the context generally provide two types of APIs:
The key point is that, in both cases, everything within the context is encapsulated within the library, and is never referenced directly by the application. |
I have restored the status quo for HTTP processing for now, which should address this regression. |
Previously, in spring 5.1,
org.springframework.core.codec.Encoder
andDecoder
implementations could take advantage of the reactor subscriberContext
, since all methods returned aMono
orFlux
.In spring 5.2, the following synchronous methods were added (as part of #22782):
Encoder
...DataBuffer encodeValue(T value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints)
Decoder
...T decode(DataBuffer buffer, ResolvableType targetType, MimeType mimeType, Map<String, Object> hints)
These new methods are called instead of the older methods in various places. E.g.
EncoderHttpMessageWriter.write
callsencoder.encodeValue
in spring 5.2, where it previously calledencoder.encode
in spring 5.1. See also this comment.These new methods do not provide access to the subscriber
Context
(since they don't return aMono
/Flux
). And there is also no way to force all callers to go back to the previous behavior of calling the old methods which do provide access to theContext
.Therefore, previous Encoder/Decoder implementations that utilized the subscriber
Context
are now broken in spring 5.2.I'd like for the subscriber Context to be available in all of the encode*/decode* methods in an Encoder/Decoder.
Perhaps the Context could be added as a hint? Or another default method added that provides the Context as an additional argument?
The text was updated successfully, but these errors were encountered: