title: Using Gson instead of Jackson in Spring Webflux
body: <p>We have many Spring MVC projects already, which all use gson instead of jackson for response body encode. Our bean classes are all written based on gson annotation. Now I am setting up a Spring Webflux restful server. It would save a lot of work if we can use the old bean classes from our Spring MVC projects.</p>
  
  <p>I have tried <code>spring.http.converters.preferred-json-mapper=gson</code> property to no avail.</p>
  
  <p>I have tried <code>HttpMessageConverter</code> bean, which is included in webflux packages, but that does not work as in the Spring MVC projects.</p>
  
  <p>I googled a lot and the only thing helpful is to implement <code>org.springframework.http.codec.HttpMessageEncoder</code> class and set it to <code>WebFluxConfigurer.configureHttpMessageCodecs()</code> method:</p>
  
  <pre><code>@Configuration
  public class WebConfiguration implements WebFluxConfigurer {
      @Override
      public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
          configurer.customCodecs().decoder(new GsonHttpMessageDecoder());
          configurer.customCodecs().encoder(new GsonHttpMessageEncoder());
      }
  
      private static class GsonHttpMessageEncoder implements HttpMessageEncoder {
          ...
      }
  
      private static class GsonHttpMessageDecoder implements HttpMessageDecoder {
          ...
      }
  }
  </code></pre>
  
  <p>I haven't try this out yet, since it is a little complex. Is there some easy way to replace jackson with gson in Spring Webflux?</p>
  
  <p>Any help is appreciated.</p>