It would be great if a mark set on a org.bson.BsonReader could be unset. Right now only resetiing to the mark(ed) position is possible.
My use case(s):
use case 1)
I wrote a reflection based org.bson.codecs.Codec that uses the new MongoDB java driver. Within the mongo database any inserted entity holds a field with the type (or name or...) of the correct Java-Pojo this entity maps to. When reading entities from the mongo I first need to read that type-property, then I create the java-Pojo instance and then I reset the mark to re-read all remaining fields into the newly created Java-instance. I am aware of the fact that I could have used the DocumentCodec provided by the mongo driver for that purpose, reading the whole entity as Document and then start to look out for the needed information within that Map-structure. This would imply double conversion hence double work hence less performance. And I would like to avoid this behaviour.
Now, in most cases the first field read is actually the type and I do not need to reset the mark. In this case I would like to unset the mark instead.
use case 2)
While decoding any decoder may internally mark the reader itself in order to apply logic as described above. Unfortunately the BsonReader is not capable of setting more than one mark at a time. An exception is being thrown if a mark is set more often. My desired behaviour would be: Any mark set can be reset AND unset.
The main issue here is, that I cannot be sure that I don’t know if the nested decoder uses a mark itself.
I hope I did not misunderstood the concept behind the BSONReader logic in general. If so, please make me aware of my wrong thinking.