Skip to content

Apply codecs auto-configuration to webflux server and webclient #9166

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

Closed
bclozel opened this issue May 11, 2017 · 6 comments
Closed

Apply codecs auto-configuration to webflux server and webclient #9166

bclozel opened this issue May 11, 2017 · 6 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented May 11, 2017

For Spring MVC, the HttpMessageConvertersAutoConfiguration configures the appropriate message converters for the server and the client (RestTemplate).

We should do the same for WebFlux, using ServerCodecConfigurer and ClientCodecConfigurer.

@snicoll
Copy link
Member

snicoll commented Jun 12, 2017

Interesting convo in #9485

@alimate
Copy link
Contributor

alimate commented Jun 16, 2017

Probably the same issue

@bclozel
Copy link
Member Author

bclozel commented Jun 19, 2017

Some changes are required in Framework to consistently apply codec configuration on both client and server sides, see SPR-15682.

@bclozel bclozel changed the title Auto-configure codecs and apply boot properties in WebFlux Apply codecs auto-configuration to webflux server and webclient Jun 20, 2017
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 20, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClientBuilder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 20, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClientBuilder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 20, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClientBuilder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 21, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClientBuilder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 22, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClientBuilder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 22, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClient.Builder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 23, 2017
This commit introduces `CodecCustomizer`, a new callback-based interface
for customizing the codecs configuration for WebFlux server and client.

Instances of those customizers are applied to the `WebClient.Builder`
and to the `WebFluxAutoConfiguration` (which deals with both WebFlux and
WebFlux.fn).

For now, only Jackson codecs are auto-configured, by getting the
`ObjectMapper` instance created by Spring Boot. Other codecs can be
configured as soon as WebFlux supports those.

Closes spring-projectsgh-9166
bclozel added a commit to bclozel/spring-boot that referenced this issue Jun 23, 2017
This commit applies what's been done in spring-projectsgh-9166 for WebFlux client and
server, but for the `WebTestClient` auto-configuration.

`WebTestClient` can be configured for mock or integration tests and this
change applies `CodecCustomizer` beans to the client being built.

Closes spring-projectsgh-9577
bclozel added a commit to bclozel/spring-boot that referenced this issue Jul 3, 2017
This commit applies what's been done in spring-projectsgh-9166 for WebFlux client and
server, but for the `WebTestClient` auto-configuration.

`WebTestClient` can be configured for mock or integration tests and this
change applies `CodecCustomizer` beans to the client being built.

Closes spring-projectsgh-9577
@bclozel bclozel closed this as completed in 6477720 Jul 3, 2017
bclozel added a commit that referenced this issue Jul 7, 2017
This commit adds new reference documentation sections about WebFlux
support in Spring Boot:

* Support for multiple HTTP servers (gh-8403)
* `CodecCustomizer` and JSON codecs (gh-8897, gh-9166)
* `WebClient.Builder` auto-configuration (gh-9522)
* Tests with `@WebFluxTest` (gh-8401)
* `WebTestClient` auto-configuration (gh-8399)
* Support for Thymeleafi and Mustache templating (gh-8124, gh-8648)
* Choose another HTTP server with WebFlux (closes gh-9690)
@bjornharvold
Copy link

Apologies, I am looking everywhere in the Spring Boot documentation and I cannot find any reference to how to get the WebTestClient to pick up my custom objectMapper. I am using Spring Boot 2 and my custom object mapper is not being used. Is there specific configuration required?

I am assuming this ticket fixed it somehow.

Cheers

@bclozel
Copy link
Member Author

bclozel commented Mar 19, 2018

If you inject a WebTestClient in your tests, it should be customized with codecs automatically.
If your application declares an ObjectMapper beans, it should override the opinion provided by Spring Boot and be picked up in the HTTP message conversion and client codecs configuration.

If it's not the case, please create a new issue with a small repro project I can take a look at.

Thanks!

@bjornharvold
Copy link

bjornharvold commented Mar 20, 2018

Hi @bclozel

I did what I saw in the other ticket that started this and added:

@Bean
    Jackson2JsonEncoder jackson2JsonEncoder() {
        return new Jackson2JsonEncoder(objectMapper());
    }

    @Bean
    Jackson2JsonDecoder jackson2JsonDecoder() {
        return new Jackson2JsonDecoder(objectMapper());
    }

    @Bean
    WebFluxConfigurer webFluxConfigurer(Jackson2JsonEncoder encoder, Jackson2JsonDecoder decoder) {
        return new WebFluxConfigurer() {
            @Override
            public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
                configurer.defaultCodecs().jackson2JsonEncoder(encoder);
                configurer.defaultCodecs().jackson2JsonDecoder(decoder);
            }
        };
    }

to my mock setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants