public class TreeSetDecodingBugPoc {
|
public static void main(String... args) {
|
CodecRegistry registry = fromRegistries(
|
MongoClientSettings.getDefaultCodecRegistry(),
|
fromProviders(PojoCodecProvider.builder().automatic(true).build()));
|
|
MongoClient client = MongoClients.create();
|
Example example = new Example(new TreeSet<>(List.of("one", "two")));
|
client.getDatabase("exampleDb").getCollection("exampleColl", Example.class).withCodecRegistry(registry).insertOne(example);
|
Example insertedExample = client.getDatabase("exampleDb").getCollection("exampleColl", Example.class).withCodecRegistry(registry).find().first();
|
System.out.println(insertedExample.getExample());
|
}
|
|
public static class Example {
|
@BsonProperty("example")
|
public SortedSet<String> example = new TreeSet<>();
|
|
@BsonCreator
|
public Example(@BsonProperty("example") TreeSet<String> example) {
|
this.example = example;
|
}
|
|
@BsonProperty("example")
|
public SortedSet<String> getExample() {
|
return this.example;
|
}
|
|
@BsonProperty("example")
|
public void setExample(SortedSet<String> example) {
|
this.example = example;
|
}
|
}
|
}
|