Class NodeDocumentCodec

  • All Implemented Interfaces:
    org.bson.codecs.Codec<NodeDocument>, org.bson.codecs.Decoder<NodeDocument>, org.bson.codecs.Encoder<NodeDocument>

    public class NodeDocumentCodec
    extends java.lang.Object
    implements org.bson.codecs.Codec<NodeDocument>
    Custom codec for MongoDB to transform a stream of BSON tokens into a NodeDocument. This custom codec provides two benefits compared to using a standard Mongo codec.
    • The standard codecs produce objects from the Mongo client API (BasicDBObject or BsonDocument or Document) which have then to be converted into NodeDocuments (OAK API). This custom codec creates directly a NodeDocument, thereby skipping the intermediate object. This should be more efficient and reduce the pressure on the GC.
    • Allows estimating the size of the document while reading it, which will have a negligible overhead (as compared with doing an additional traverse of the object structure to compute the size).
    • Method Detail

      • decode

        public NodeDocument decode​(org.bson.BsonReader reader,
                                   org.bson.codecs.DecoderContext decoderContext)
        Specified by:
        decode in interface org.bson.codecs.Decoder<NodeDocument>
      • encode

        public void encode​(org.bson.BsonWriter writer,
                           NodeDocument value,
                           org.bson.codecs.EncoderContext encoderContext)
        Specified by:
        encode in interface org.bson.codecs.Encoder<NodeDocument>
      • getEncoderClass

        public java.lang.Class<NodeDocument> getEncoderClass()
        Specified by:
        getEncoderClass in interface org.bson.codecs.Encoder<NodeDocument>