java types in org.bson.BSONObject

…衆ロ難τιáo~ 提交于 2019-12-03 21:18:29

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!