In order to get our Model in MongoDB we used google gson to convert our model into JSON first and then we used the JSON util parse method from MongoDB to parse our generated JSON string to a DBObject which you can put in your MongoDB. I don't know about performance to be honest.
还有一个相当新的 BSON4Jackson 项目,它允许使用 Jackson 用于处理 BSON 数据。这意味着完整的数据绑定(到/从 POJO)、树模型,甚至流式(增量)读/写都可以使用 BSON 格式完成。
There is also a rather new BSON4Jackson project, which allows one to use Jackson for handling BSON data. This means full data binding (to/from POJOs), tree model, even streaming (incremental) reading/writing to degree it can be done with BSON format.
发布评论
评论(5)
您可以使用适用于 Java 的 MongoDB 驱动程序来存储 BSON 对象,然后将其转换为
String
,然后您可以用JSONObject
。例如,以下是我创建常规文档的方法:
然后,要获取对象的
String
表示形式,只需调用:用
JSONObject
包装它并获取日期属性,它应该以 BSON 兼容的格式返回它。结果输出类似于:
You can use the MongoDB driver for Java to store a BSON object, then convert that to a
String
which you can then wrap withJSONObject
.For example, here's how I'll create a regular document:
Then, to get a
String
representation of the object, simply call:Wrap it with a
JSONObject
and get the date attribute, which should return it in a BSON-compliant format.The resulting output is something like:
BSON 站点 指向 这个
如果你想从 MongoDB 使用它,请查看 此示例
The BSON site is pointing at this
If you want to use it from MongoDB, take a look at this example
为了在 MongoDB 中获取模型,我们首先使用 google gson 将模型转换为 JSON,然后使用 来自 MongoDB 的 JSON util 解析方法 将我们生成的 JSON 字符串解析为 DBObject,您可以将其放入 MongoDB 中。说实话,我不知道性能如何。
In order to get our Model in MongoDB we used google gson to convert our model into JSON first and then we used the JSON util parse method from MongoDB to parse our generated JSON string to a DBObject which you can put in your MongoDB. I don't know about performance to be honest.
还有一个相当新的 BSON4Jackson 项目,它允许使用 Jackson 用于处理 BSON 数据。这意味着完整的数据绑定(到/从 POJO)、树模型,甚至流式(增量)读/写都可以使用 BSON 格式完成。
There is also a rather new BSON4Jackson project, which allows one to use Jackson for handling BSON data. This means full data binding (to/from POJOs), tree model, even streaming (incremental) reading/writing to degree it can be done with BSON format.
还有 ebson。我没试过...
There is also ebson. I've not tried it...