public class JAVA4667 {
|
|
public record Employee(@BsonId ObjectId id, List<Address> addresses) {}
|
public record Address(String addressId, String city, String state) {}
|
|
public static void main(String[] args) {
|
var mongoClient = MongoClients.create();
|
|
var database = mongoClient.getDatabase("test");
|
var collection = database.getCollection("employee", Employee.class);
|
|
collection.drop();
|
|
collection.insertOne(new Employee(new ObjectId("62ad33d33fde2c00f75e0bc2"),
|
List.of(new Address("1", "NYC", "NY"))));
|
|
var employee = collection.find().first();
|
System.out.println(employee);
|
System.out.println(employee.addresses.get(0).getClass());
|
}
|
}
|