mongodb的ObjectId默认序列化为bean对象,如果需要转换为json字符对象,配置如下
@Configuration
public class JacksonConfig implements InitializingBean {@Resourceprivate ObjectMapper objectMapper;@Overridepublic void afterPropertiesSet() {SimpleModule simpleModule = new SimpleModule();//指定mongodb ObjectId 序列化方式simpleModule.addSerializer(ObjectId.class, ToStringSerializer.instance);objectMapper.registerModule(simpleModule);}
}