[英]Save an embedded document _id as ObjectId but display it as a String
I want to save the _id in Review class as an ObjectId but when I query it I want it to be displayed as a String and not the {"timestamp", "machineIdentifier", etc.}我想将 Review 类中的 _id 保存为 ObjectId,但是当我查询它时,我希望它显示为字符串而不是 {"timestamp"、"machineIdentifier" 等}
Here are the classes I made:以下是我制作的课程:
@Document
public class Catalog {
....
private List<Review> reviews;
....
}
public class Review {
@Id
private ObjectId _id = new ObjectId();
private String userid;
private String username;
private String reviewstring;
}
The class Review in the mongodb is an embedded document. mongodb 中的 Review 类是一个嵌入式文档。
When I query for a certain review with the _id as a String, it returns null.当我使用 _id 作为字符串查询某个评论时,它返回 null。 How can I display the ObjectId as a String during queries but let it remain as an ObjectId?
如何在查询期间将 ObjectId 显示为 String 但让它保留为 ObjectId?
@JsonSerialize(使用 = ToStringSerializer.class)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.