private <T> void encodeValue(BsonOutput output, Codec<T> codec, T value) { try (BsonBinaryWriter writer = new BsonBinaryWriter(output)) { writer.writeStartDocument(); writer.writeName("value"); codec.encode(writer, value, EncoderContext.builder().build()); writer.writeEndDocument(); writer.close(); } }
@Override public BsonOutput writeToBsonOutput(Object object) { if (object == null) { return null; } BsonOutput bsonOutput = new BasicOutputBuffer(); BsonWriter bsonBinaryWriter = new BsonBinaryWriter(new BsonWriterSettings(bsonMapperConfig.getMaxMapperLayerNum()), new BsonBinaryWriterSettings(bsonMapperConfig.getMaxDocumentSizeForBsonWriter()), bsonOutput); BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonBinaryWriter, object); return bsonOutput; }
BsonOutput writeToBsonOutput(Object object);