[JAVA-2870] Annotations example in Java driver POJO page seems incomplete Created: 29/May/18  Updated: 28/Oct/23  Resolved: 21/Jun/18

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 3.8.0

Type: Improvement Priority: Minor - P4
Reporter: Nic Cottrell Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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:"

 

 



 Comments   
Comment by Githook User [ 21/Jun/18 ]

Author:

{'username': 'rozza', 'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com'}

Message: Docs: Updated Person annotation example

JAVA-2870
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/27e5321fd84cdb5fc80c57d98d295156d3ae69f0

Comment by Ross Lawley [ 04/Jun/18 ]

Hi nicholas.cottrell,

Thanks for the ticket, you're correct the Person instance in the annotations section is missing the annotation.

Ross

Generated at Thu Feb 08 08:58:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.