org.bson.BSONObject 中的 java 类型

发布于 2024-09-24 00:53:53 字数 439 浏览 0 评论 0原文

我目前正在学习 BSON java mongodb 库,我正在尝试将 org.bson.BSONObject 转换为 XML,以便使用 XSLT 样式表进行转换。

我可以在 Mongodb 的 BSONObject 中找到哪种 java 类型作为值?当然会有:

  • BSONObject (内部文档)
  • java.lang.String
  • ???

其他人是什么? BigDecimal 和 BigInteger ?布尔值、整数、长整型、双精度型?时间戳..等等...??

谢谢,

皮埃尔

I'm currently learning the BSON java library for mongodb and I'm trying to transform a org.bson.BSONObject into XML in order to transform it with a XSLT stylesheet.

What kind of java types can I find as values in a BSONObject from a Mongodb ? Of course there will be:

  • BSONObject (internal doc)
  • java.lang.String
  • ???

what are the others ? BigDecimal and BigInteger ? boolean, int, long, double ? Timestamp.. etc... ??

thanks,

Pierre

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2024-10-01 00:53:53

也必须搜索它,但根据this mongodb-dev 后映射是这样完成的:

 NULL            null
 UNDEFINED       null
 BOOLEAN         Boolean
 NUMBER          Double
 NUMBER_INT      Integer
 NUMBER_LONG     Long
 SYMBOL          String
 STRING          String
 OID             mongodb ObjectID
 REF             DBPointer
 DATE            Date
 REGEX           Pattern
 BINARY          DBBinary
 CODE            (exception)
 ARRAY           DBList
 OBJECT          DBObject or DBRef
 TIMESTAMP       DBTimestamp
 MINKEY          String: "MinKey"
 MAXKEY          String: "MaxKey" 

This mongodb.org 上的文章是也是一个很好的资源。

编辑:查看源代码:org.bson.types.* 有许多 BSON 类型的类。 org.bson.BSONDecoder 正在解码 BSON 字符串并执行上面列出的映射。

Had to search for it too, but according to this mongodb-dev post mapping is done like this:

 NULL            null
 UNDEFINED       null
 BOOLEAN         Boolean
 NUMBER          Double
 NUMBER_INT      Integer
 NUMBER_LONG     Long
 SYMBOL          String
 STRING          String
 OID             mongodb ObjectID
 REF             DBPointer
 DATE            Date
 REGEX           Pattern
 BINARY          DBBinary
 CODE            (exception)
 ARRAY           DBList
 OBJECT          DBObject or DBRef
 TIMESTAMP       DBTimestamp
 MINKEY          String: "MinKey"
 MAXKEY          String: "MaxKey" 

This article on mongodb.org is a good resource for it, too.

Edit: Had a look at the source: org.bson.types.* is having a number of classes for BSON types. org.bson.BSONDecoder is decoding a BSON string and does the mapping listed above.

赏烟花じ飞满天 2024-10-01 00:53:53

在 BSON 上操作的一种替代方法是使用 Jackson JSON 处理器;虽然默认情况下它在 JSON 上运行,但有一些扩展可以在 BSONXML。由于 Jackson 进行数据绑定,因此您可以将 BSON 数据绑定到 Java POJO(使用 bson4jackson)并以 XML 形式写出(使用 jackson-xml-databind)。
转换将非常简单:

String xml = xmlMapper.writeValue(bsonMapper.readValue(bsonData, MyPojo.class));

如果您拥有或可以创建映射所有属性的 MyPojo;或者如果没有指定 Map.class 作为要绑定的中间类型。

One alternative way to operate on BSON would be to use Jackson JSON processor; although by default it operates on JSON, there are extensions to use it both on BSON and XML. Since Jackson does data binding, you can bind BSON data into Java POJOs (with bson4jackson) and write out as XML (with jackson-xml-databind).
Transformation would be as simple as:

String xml = xmlMapper.writeValue(bsonMapper.readValue(bsonData, MyPojo.class));

if you have, or can create, MyPojo that maps all properties; or if not by specifying Map.class as the intermediate type to bind to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文