[英]Change MongoDb ObjectId _id to string in Micronaut using java
I have below Pojo class for the mongo entity我有下面的 Pojo class 用于 mongo 实体
public class Product {
@BsonProperty("_id")
@BsonId
private ObjectId id;
private String name;
private float price;
private String description;
}
when I fetch the mongo result as per the below code当我按照下面的代码获取 mongo 结果时
var item = Flowable.fromPublisher(this.repository.getCollection("product", Product.class).find()).blockingIterable();
The id id mapped something like this id id映射了这样的东西
However, in the database the id is something like this但是,在数据库中,id 是这样的
How do I map this id in the correct way, I am using Micronaut framework with java 15我如何以正确的方式使用 map 这个 id,我正在使用 Micronaut 框架和 java 15
You can add simple getter:您可以添加简单的吸气剂:
@JsonGetter
public String getObjectId() {
return id.toString();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.