Improved MongoDB compatibility for bson4jackson

Version 1.2.0 of bson4jackson has just been released. bson4jackson adds support for BSON, a binary representation of JSON, to the Jackson JSON processor. Thanks to contributions from the community, the latest release of bson4jackson now includes better support for MongoDB.

Gergő Ertli has fixed the support for the ObjectId type. Object IDs are used as the primary key for MongoDB documents.

Support for the UUID type has been added by Ed Anuff. He added a new module that can be registered with Jackson’s ObjectMapper:

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

Thanks to the contribution by James Roper the BsonParser class now supports the new HONOR_DOCUMENT_LENGTH feature, which makes the parser honour the first 4 bytes of a document that usually contain the document’s size. Of course, this only works if BsonGenerator.Feature.ENABLE_STREAMING has not been enabled during document generation.

This feature can be useful for reading consecutive documents from an input stream produced by MongoDB. You can enable it as follows:

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

Apart from that, a lot of other minor bugs have been fixed. The library has been tested with Jackson 1.7 up to 1.9.

More information

For a complete description of bson4jackson (including how to download it), have a look at my tutorial.

Profile image of Michel Krämer

Posted by Michel Krämer
on 17 December 2011

Next post

bson4jackson 2.0 has just been released!

I’m excited to announce bson4jackson 2.0! The new version supports Jackson 2.0. Also, with a little help from the community, a few bugs have been fixed. Upgrading is recommended for all users.

Previous post

Build Scala projects with Eclipse Buckminster

Buckminster is a tool to build Eclipse RCP applications. It contains a lightweight Eclipse SDK and features but no means to build Scala projects yet. This post tries to bridge this gap.

Related posts

Binary JSON with bson4jackson

This post introduces the open-source library bson4jackson, which is an extension to the Jackson JSON processor. It enables you to parse and generate documents in a binary JSON format called BSON.

bson4jackson 2.9.2

This blog post summarizes the changes that came with the latest bson4jackson updates. Highlights are support for Decimal128, refactored serializers and deserializers, as well as support for Jackson 2.8 and 2.9.

bson4jackson 2.11.0

This version is a maintenance release that updates Jackson and fixes some minor issues. Performance of the UTF-8 decoder has been improved and precision of BigDecimals has been increased. Updating is recommended for all users.