Atualização para que esteja usando a API nova do Mongo 4.4.5
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-core -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>4.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/bson -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.2.3</version>
</dependency>
public void salvar(Aluno aluno) {
Codec<Document> codec = MongoClientSettings.getDefaultCodecRegistry().get(Document.class);
AlunoCodec alunoCodec = new AlunoCodec(codec);
CodecRegistry registro =
CodecRegistries.fromRegistries(CodecRegistries.fromCodecs(alunoCodec),
MongoClientSettings.getDefaultCodecRegistry());
MongoClientSettings opcoes = MongoClientSettings.builder()
.codecRegistry(registro).build();
MongoClient mongoClient = MongoClients.create(opcoes);
MongoDatabase database = mongoClient.getDatabase("test");
MongoCollection<Aluno> alunos = database.getCollection("alunos", Aluno.class);
alunos.insertOne(aluno);
mongoClient.close();
}