spring boot webflux json序列化疑问
遇到的问题:使用spring-boot-starter-webflux
开发的时候使用默认的jackson
做JSON的序列化与反序列化,但是当我的javaBean里的属性使用的是驼峰命名法,我想序列化成JSON字符串后得到匈牙利命名法的json key, 但是失败了,这是我的配置代码
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
请问这是为什么呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Based on spring boot Javadoc, a bean of type
JacksonHttpMessageConvertersConfiguration
needs an injectedObjectMapper
object, thereafter, all you need is to define a bean of type ObjectMapper, like this: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.