BSON library for java?

We have good JSON support in java http://blog.locut.us/main/2009/10/14/which-is-the-best-java-json-library.html , but what about BSON.

In which library do you know BSON support for java? Obviously, it must be effective at runtime.

+13
java mongodb bson
Sep 07 '10 at 6:49
source share
5 answers

BSON site points to this

If you want to use it with MongoDB, see this example.

+2
Sep 07 '10 at 7:19
source share

You can use the MongoDB driver for Java to store the BSON object, and then convert it to String , which can then be wrapped using JSONObject .

For example, here's how I create a regular document:

 BasicDBObject obj = new BasicDBObject(); obj.put("name", "Matt"); obj.put("date", new Date()); 

Then, to get the String representation of the object, simply call:

 String bsonString = obj.toString(); 

Wrap it with JSONObject and get the date attribute, which should return it in a BSON compatible format.

 JSONObject newObject = new JSONObject(bsonString); System.out.println(newObject.get("date")); 

The resulting result looks something like this:

 {"$date":"2012-08-10T05:22:53.872Z"} 
+6
Jul 28 '12 at 10:30
source share

There is also ebson . I have not tried ...

+2
Nov 17 '11 at 21:17
source share

To get our model in MongoDB, we used google gson to first convert our model to JSON, and then we used JSON used the analysis method from MongoDB to parse our generated JSON string into DBObject, which you can put in your MongoDB. I don't know about performance, to be honest.

+1
Sep 07 '10 at 7:24
source share

There is also a fairly new BSON4Jackson project that allows you to use Jackson to process BSON data. This means full data binding (to / from POJO), a tree model, and even streaming (incremental) read / write to the extent that it can be done using the BSON format.

0
Jan 11 2018-11-11T00:
source share



All Articles