Java MongoDb获取id作为时间戳,但需要十六进制字符串

Java MongoDb获取id作为时间戳,但需要十六进制字符串,java,spring,mongodb,pojo,Java,Spring,Mongodb,Pojo,我正在为名为Schema的集合执行CRUD,需要以十六进制字符串的形式检索de_id,但是当我使用collection.find()时,我得到的是时间戳和日期,而不是字符串 我收到了这个结构: { "_id": { "timestamp": 1604689898, "date": "2020-11-06T19:11:38.000+00:00" } }

我正在为名为Schema的集合执行CRUD,需要以十六进制字符串的形式检索de_id,但是当我使用collection.find()时,我得到的是时间戳和日期,而不是字符串

我收到了这个结构:

{
"_id": {
            "timestamp": 1604689898,
            "date": "2020-11-06T19:11:38.000+00:00"
        }
}
{
"_id": "5fa5a085a4b09b307d53ed57"
}
但我需要这样的东西:

{
"_id": {
            "timestamp": 1604689898,
            "date": "2020-11-06T19:11:38.000+00:00"
        }
}
{
"_id": "5fa5a085a4b09b307d53ed57"
}
以下是我的配置

Pom.xml


4.0.0
org.springframework.boot
spring启动程序父级
2.3.4.1发布
co.com.itau
加密mongodb java ms
0.0.1-快照
加密mongodb java ms
使用CSFLE从mongoDB保存和读取数据的微服务
1.8
3.5.41
3.0.0
org.springframework.boot
spring启动程序数据mongodb
org.springframework.boot
弹簧启动启动器验证
org.springframework.plugin
spring插件核心
2.0.0.1版本
org.springframework.boot
弹簧启动启动器数据rest
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
SpringBootStarterWeb服务
org.projectlombok
龙目
真的
com.google.code.gson
格森
org.springframework.boot
弹簧靴开发工具
伊奥·斯普林福克斯
springfox启动程序
${swagger.version}
org.springframework.cloud
spring cloud starter netflix hystrix
2.1.2.1发布
org.springframework.plugin
spring插件核心
2.0.0.1版本
org.mongodb
mongodb隐窝
1.0.1
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.boot
springbootmaven插件
openshift
io.fabric8
fabric8 maven插件
${version.fabric8 maven plugin}
fmp
包裹
资源
建造
伊斯塔格
redhat-openjdk18-openshift:1.2
MongoClient配置

CodecRegistry pojoCodecRegistry=fromProviders(PojoCodecProvider.builder().automatic(true.build());
CodecRegistry CodecRegistry=fromRegistries(MongoClientSettings.getDefaultCodecRegistry(),pojoCodecRegistry);
MongoClient mongoauax=MongoClients.create(MongoClientSettings.builder())
.applyConnectionString(新连接字符串(连接字符串))
.codecRegistry(codecRegistry)
.build());
返回MongouAX;
模式模型

@数据
@AllArgsConstructor
@诺尔格构装师
公共类模式{
@JsonProperty(“\u id”)
@SerializedName(“\u id”)
公共对象id;
公共字符串数据库;
公共字符串集合;
公共文档模式;
}
**存储库**

@存储库
公共类SchemaMongoRepository实现SchemaRepository{
@值(${mongodb.schema.db}”)
私有字符串mongoDatabase;
@值(${mongodb.schema.collection}”)
私有字符串mongoCollection;
私有静态最终记录器Logger=LoggerFactory.getLogger(schemamonogrepository.class);
@自动连线
私有MongoClient MongoClient;
@自动连线
私钥;
私有MongoCollection方案集合;
@施工后
void init(){
schemaCollection=mongoClient.getDatabase(mongoDatabase).getCollection(mongoCollection,Schema.class);
}
@凌驾
公共列表getSchemas(){
List schemaList=new ArrayList();
FindTable结果=schemaCollection.find();
for(架构currentSchema:result){
添加(currentSchema);
}
回归图式主义;
}
}

您面临的问题是ObjectId被扩展(反序列化)。我们将其序列化。在pom中添加此依赖项

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.11.0.rc1</version>
</dependency>
这将为您提供预期的输出