-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: POJO
Java is adding support for records. See https://openjdk.java.net/jeps/359 for a description. The feature will be in preview in Java 14 and if all goes well will be added to the language.
Update: a second preview will be included in Java 15 and is described in https://openjdk.java.net/jeps/384.
The PojoCodecProvider does not support records because records don't follow Java Beans conventions. Rather than generating getter methods that are prefixed with "get", the getter names are identical to the property names, e.g. a record like
public record Animal(@BsonId ObjectId id, @BsonProperty("name") String name, @BsonProperty("age") int age) { }
will generate a JVM class like:
public class Animal extends java.lang.Record { @BsonId private final ObjectId id @BsonProperty("name") private final String name; @BsonProperty("age") i private final int age; public Animal(@BsonId ObjectId id, @BsonProperty("name") String name, @BsonProperty("age") int age) { this.objectId = objectId; this.name = name; this.age = age; } @BsonId public ObjectId id() { return id; } @BsonProperty("name") public String name() { return name; } @BsonProperty("age") public int age() { return age; } // hashCode, equals, toString