Details
-
Improvement
-
Resolution: Fixed
-
Minor - P4
-
None
-
None
-
None
Description
See http://mongodb.github.io/mongo-java-driver/3.7/bson/pojos/
The Person example seems to be wrong. Doesn't the personId field need a @BsonId annotation? Also, maybe we could demonstrate the other annotations here just to be extra clear? Something like:
import org.bson.codecs.pojo.annotations.*; |
|
|
@BsonDiscriminator
|
public final class Person { |
|
|
@BsonId |
public String personId; |
public String firstName; |
@BsonProperty("surname") |
public String lastName; |
|
|
@BsonIgnore |
public String password; |
|
@BsonProperty(useDiscriminator = true) |
public Address addr; |
|
public Person(){ |
}
|
|
|
}
|
giving
{ "_id": "1234567890", "_t": "Person", "surname": "Alan", "lastName": "Turing", |
"address": { "_t": "Address", "address": "The Mansion", "street": "Sherwood Drive", "town": "Bletchley", "postcode": "MK3 6EB" } } |
Also weird capitalization in "The Person POJO *W*ill produce BSON similar to:"