Improved MongoDB compatibility for bson4jackson

Ver­sion 1.2.0 of bson4­jack­son has just been re­leased. bson4­jack­son adds sup­port for BSON, a bin­ary rep­res­ent­a­tion of JSON, to the Jack­son JSON pro­cessor. Thanks to con­tri­bu­tions from the com­munity, the latest re­lease of bson4­jack­son now in­cludes bet­ter sup­port for Mon­goDB.

Gergő Ertli has fixed the sup­port for the ObjectId type. Ob­ject IDs are used as the primary key for Mon­goDB doc­u­ments.

Sup­port for the UUID type has been ad­ded by Ed Anuff. He ad­ded a new mod­ule which can be re­gistered to Jack­son’s ObjectMapper:

ObjectMapper om = new ObjectMapper(new BsonFactory());
om.registerModule(new BsonUuidModule());

Thanks to the con­tri­bu­tion by James Roper the BsonParser class now sup­ports the new HONOR_DOCUMENT_LENGTH fea­ture which makes the parser honor the first 4 bytes of a doc­u­ment which usu­ally con­tain the doc­u­ment’s size. Of course, this only works if Bson­Gen­er­ator.­Fea­ture.­EN­ABLE_STREAM­ING has not been en­abled dur­ing doc­u­ment gen­er­a­tion.

This fea­ture can be use­ful for read­ing con­sec­ut­ive doc­u­ments from an in­put stream pro­duced by Mon­goDB. You can en­able it as fol­lows:

BsonFactory fac = new BsonFactory();
BsonParser parser = (BsonParser)fac.createJsonParser(...);

Apart from that, a lot of other minor bugs have been fixed. The lib­rary has been tested with Jack­son 1.7 up to 1.9.

More information

For a com­plete de­scrip­tion of bson4­jack­son (in­clud­ing how to down­load it) have a look at my tu­torial.

Posted by Michel Krämer
on December, 17th 2011.