Skip to content

Using Morphia and mapped models to convert BSON to POJO #2695

Closed Answered by evanchooly
antoni-gierczak asked this question in Q&A
Discussion options

You must be logged in to vote

OK. So this is going to deep in to the weeds of internal stuff that should get you where you're going but I wouldn't recommend relying on it because internals can always change without warning yadda yadda yadda. But enough with the safe harbor disclaimers...

So to start off with, you're going to have a file with BSON bytes, yeah? First off, you'll want to read that in to memory. Read each bson in to a byte[] and then you can read that in to a BsonDocument:

var bsonDocument = new BsonDocumentCodec()
   .decode(new BsonBinaryReader(ByteBuffer.wrap(bytes)
   .order(ByteOrder.LITTLE_ENDIAN)), DecoderContext.builder().build());

Once that's done, you'll have a BsonDocument and you can create a D…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by antoni-gierczak
Comment options

You must be logged in to vote
1 reply
@evanchooly
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants