MongoDB SpringBoot ObjectId序列化json为String
mongodb的ObjectId默认序列化为bean对象,如果需要转换为json字符对象,配置如下@Configurationpublic class JacksonConfig implements InitializingBean {@Resourceprivate ObjectMapper objectMapper;@Overridepublic void afterPropertiesSe
·
mongodb的ObjectId默认序列化为bean对象,如果需要转换为json字符对象,配置如下
@Configuration
public class JacksonConfig implements InitializingBean {
@Resource
private ObjectMapper objectMapper;
@Override
public void afterPropertiesSet() {
SimpleModule simpleModule = new SimpleModule();
//指定mongodb ObjectId 序列化方式
simpleModule.addSerializer(ObjectId.class, ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
}
}
更多推荐
已为社区贡献6条内容
所有评论(0)