-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Spring Reactive Web uses kotlin serialization over jackson for its own classes, and it's very hard to change #28856
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
Comments
Currently Kotlin serialization is based on classpath detection only. I'm just wondering, should it be on the classpath, and is there a way to exclude it? Or otherwise it would make sense to provide a way to disable it. @sdeleuze what do you think? @martypitt, if you register a custom Encoder or Decoder (e.g. Jackson), it is ahead of default ones in the order, so that provides another option to influence the order. |
@martypitt Could you please share more about your use case for using Jackson on classes annotated with |
Sure. We use JSON for responses out to web requests, as part of our "public" api. Several classes are intended for serializaton in both scenarios. |
Could you please clarify where the Kotlinx serialization dependency come from? Declared directly in your project (for which use case) or via a third party dependency (which one)? |
Sure. In our spring boot app, we have the following: <dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-serialization-cbor</artifactId>
</dependency> We use this for serializing efficient messages between our own components. Not sure if I've answered the question you're asking - please let me know if I can provide any other info. |
Yes you did, but our classpath detection is based on |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
In response to the following reply by @rstoyanchev :
@sdeleuze As you can see, I'm not the only one who's having problem with this default and unexpected classpath-dependent behavior. This is seems like the same problem I described in #32382 and #32384. Could we maybe have a wider discussion about this problem? I would also very much appreciate some input here from your fellow developers. Thanks. |
For anybody stumbling upon this thread through a search engine while looking for a solution to this problem in Spring Boot, see these answers for a workaround: |
I have the opposite problem -- Jackson is always used in favor of kotlinx-serialization. Man, Spring is... frustrating. |
@rocketraman Check here, to use kotlinx serialization:
|
Affects: Spring 5.3.21
This is somewhat related to #26321 - Spring using kotlin serialization over jackson (but not the same, as that's for WebMVC).
In Reactive Web, Kotlin classes that are tagged as
@Serializable
use Kotlin Serializers, not Jackson.This is a reasonable default, but changing the behaviour is very difficult, and has a few surprising side effects.
In Spring WebMVC, we could re-order the
HttpMessageConverter<>
, and put Jackson first:The contract of
WebFluxConfigurer
doesn't allow modification of the list - because theBaseCodecConfigurer
returns a new list each time:Therefore, adding any sort like in WebMVC has no effect.
Changing the Kotlin encoder to null (to try to disable), doesn't work, as
BaseDefaultCodecs
simply adds it back:The workaround I've used is to put a decorator around the configurer to re-order every single time. However, this seems awkward.
Expected / Desired Behaviour
It'd be nice if there was an easier way to configure this.
At the very least, where
BaseDefaultCodecs
overwrites the changed Kotlin serializer feels like a bug.The text was updated successfully, but these errors were encountered: