Comments (5)
Using the postProcess
hooks points offers more precise control over the end result. Perhaps not needed here, but it's the recommended approach and this sort of situation is why those methods were introduced.
from spring-boot.
Until we find time to look at this in detail, as an alternative workaround, you may want to consider defining your own HttpMessageConverters
bean that overrides postProcessConverters
and postProcessPartConverters
to filter out the unwanted converter.
from spring-boot.
@wilkinsona Thanks for the alternative workaround. Can you maybe explain what the advantage of that approach is over the workaround I shared above?
from spring-boot.
@wilkinsona Thanks! By the way, when I have overridden postProcessConverters()
, I don't also have to override postProcessPartConverters()
, correct? The latter only applies in a subset of cases, do I interpret that correctly from the code?
Based on the example you linked to, I ended up with this (in Kotlin), which indeed works as well, at least in our case:
import org.springframework.boot.autoconfigure.http.HttpMessageConverters
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.AbstractKotlinSerializationHttpMessageConverter
import org.springframework.http.converter.HttpMessageConverter
@Configuration
class MessageConvertersConfig {
/**
* Bean provider that filters out standard [HttpMessageConverter]s that we don't want Spring to use, even when the
* serde frameworks for them are detected by Spring in the classpath.
*
* With thanks to https://github.com/spring-projects/spring-boot/issues/39853#issuecomment-1984360351 and
* https://github.com/spring-projects/spring-boot/issues/1482#issuecomment-61862787
*
* Should override [org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration.messageConverters]
*/
@Bean
fun filteredMessageConverters(): HttpMessageConverters =
object : HttpMessageConverters() {
override fun postProcessConverters(converters: MutableList<HttpMessageConverter<*>>): MutableList<HttpMessageConverter<*>> {
converters.removeIf {
it is AbstractKotlinSerializationHttpMessageConverter<*>
}
return converters
}
}
}
from spring-boot.
By the way, when I have overridden
postProcessConverters()
, I don't also have to overridepostProcessPartConverters()
, correct? The latter only applies in a subset of cases, do I interpret that correctly from the code?
Yes, that's right. postProcessPartConverters()
only applies to the converters that are used by AllEncompassingFormHttpMessageConverter
. If your app isn't receiving multi-part requests, the converters used by this converter converter won't need to be customized.
Just to make sure I have understood your situation correctly, am I right in understanding that:
- Your application has Jackson on the classpath
- Your application has kotlinx.serialization on the classpath
- You are (de)serializing a type that kotlinx.serialization supports (
kotlinx.serialization.SerializersKt.serializerOrNull
returns aKSerializer
for the type) but you want Jackson to be used instead
Assuming that the above is correct, is kotlinx.serialization on the classpath for some other reason or is it there accidentally? Just trying to understand the scope of the problem and gauge how likely others are to be affected by it – this is the first time it's been raised in Boot's issues as far as I can remember.
from spring-boot.
Related Issues (20)
- Upgrade to Micrometer 1.13.0-M2
- Upgrade to Micrometer Tracing 1.3.0-M2
- Upgrade to Spring AMQP 3.1.3
- Upgrade to Spring Authorization Server 1.3.0-M3
- Upgrade to Spring Data Bom 2024.0.0-M2 HOT 1
- Upgrade to Spring Framework 6.1.5
- Upgrade to Spring GraphQL 1.3.0-RC1
- Upgrade to Spring Integration 6.3.0-M2
- Upgrade to Spring Kafka 3.2.0-M2
- Upgrade to Spring Pulsar 1.1.0-M2
- Upgrade to Spring Security 6.3.0-M3
- Upgrade to Spring Session 3.3.0-M3
- Make spring-test available to compile classpath of consumers of spring-boot-test HOT 9
- Springboot version: 2.1.1.Is RELEASE compatible with Centos8.1 HOT 1
- Override of YML lists in externalized configuration files does not work or is documented wrongly HOT 8
- Deprecate support for io.micrometer.prometheus.PrometheusMeterRegistry in favor of io.micrometer.prometheusmetrics.PrometheusMeterRegistry HOT 2
- SpringBoot 3.2 BaseStateMachineListener HOT 1
- Upgrade to Reactor Bom 2022.0.17
- Upgrade to Reactor Bom 2023.0.4
- Upgrade to Reactor Bom 2023.0.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.