0

I need to inject two different objectMapper (Jackson2ObjectMapperBuilder) config on two versions of my controller, I have tried many examples, but with webflux they don't works (with webMvc work fine).

@RestController
@RequestMapping("/v1")
public class ControllerV1 implements IController {
...
}

@RestController
@RequestMapping("/v2")
public class ControllerV2 implements IController {
...
}


@EnableReactiveMongoRepositories
public class Config extends AbstractReactiveMongoConfiguration {

    @Override
    public MongoClient reactiveMongoClient() {
        ...
    }

    @Primary
    @Bean(name = "objectMapperV1")
    public Jackson2ObjectMapperBuilder v1objectMapperBuilder() {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
        builder.propertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
        ...
        return builder;
    }

    @Bean(name = "objectMapperV2")
    public Jackson2ObjectMapperBuilder v2objectMapperBuilder() {
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
        builder.propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        ...
        return builder;
    }

}

The only mapper used is the @Primary, how to set by configuration the v2objectMapperBuilder in ControllerV2?

ps: if inject v2objectMapperBuilder in ControllerV2 and use directly obviously works, but I don't want this.

ccirim
  • 1
  • 2
  • possible duplicate https://stackoverflow.com/questions/37844101/can-you-configure-spring-controller-specific-jackson-deserialization – Toerktumlare Feb 26 '20 at 23:21
  • It's a different case. – ccirim Feb 27 '20 at 13:53
  • don't just say its a different case, if you expect help then explain what is different. The link points to the same case except for they are using web instead of webflux, but the classes are the same, interfaces are the same, implementations are the same. – Toerktumlare Feb 27 '20 at 14:08

0 Answers0