Skip to content

The new Encoder.encodeValue and Decoder.decode methods in spring 5.2 do not provide access to the Context #24441

@philsttr

Description

@philsttr

Previously, in spring 5.1, org.springframework.core.codec.Encoder and Decoder implementations could take advantage of the reactor subscriber Context, since all methods returned a Mono or Flux.

In spring 5.2, the following synchronous methods were added (as part of #22782):

  • in Encoder... DataBuffer encodeValue(T value, DataBufferFactory bufferFactory, ResolvableType valueType, MimeType mimeType, Map<String, Object> hints)
  • in 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 calls encoder.encodeValue in spring 5.2, where it previously called encoder.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 a Mono/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 the Context.

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?

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions