Spring boot webflux json serialization query

problem encountered: when developing with spring-boot-starter-webflux , use the default jackson to serialize and deserialize JSON, but when the attributes in my javaBean use hump naming, I want to serialize it into a JSON string and get the json key, of Hungarian nomenclature, but failed. This is my configuration code

.
    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        jsonConverter.setObjectMapper(objectMapper);
        return jsonConverter;
    }

excuse me, why is this?

Mar.07,2021

Based on spring boot Javadoc, a bean of type JacksonHttpMessageConvertersConfiguration needs an injected ObjectMapper object, thereafter, all you need is to define a bean of type ObjectMapper, like this:

@Bean
ObjectMapper yourMethod() {...}

Please note that, this ObjectMapper would be used for all spring de/serialization, if you want to customize only some properties or some Pojos, use the corresponding jackson annotations, which is off the topic.

Menu