Skip to content

Commit 943f6ba

Browse files
committed
DOCSP-40062: BsonProperty getters/setters (#561)
* DOCSP-40062: BsonProperty getters/setters * MM feedback (cherry picked from commit 06681df)
1 parent 83d0c17 commit 943f6ba

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

source/fundamentals/data-formats/pojo-customization.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ package:
303303
field to BSON. You can include a discriminator to serialize POJOs
304304
nested within the field.
305305

306+
.. important::
307+
308+
When applying ``@BsonProperty`` to a private field, you must also add
309+
getter and setter methods for that field to serialize and customize
310+
the field name.
311+
306312
* - ``BsonExtraElements``
307313
- Specifies the POJO field on which to deserialize all elements that are
308314
not mapped to a field. The POJO field must be one of the following
@@ -348,9 +354,16 @@ several of the preceding annotations.
348354
public Product(@BsonProperty("modelName") String name) {
349355
this.name = name;
350356
}
357+
358+
public String getName() {
359+
return this.name;
360+
}
351361

352-
// ...
362+
public void setName(String name) {
363+
this.name = name;
364+
}
353365

366+
// ...
354367
}
355368

356369
.. _bson-annotation-convention:
@@ -378,7 +391,6 @@ The annotations in the example POJO specify the following behavior:
378391
- Omit the ``relatedItems`` field and value when converting data
379392
- Use the ``Product(String name)`` constructor when instantiating the POJO
380393

381-
382394
.. _bsonextraelements-annotation-code-example:
383395

384396
BsonExtraElements Example

0 commit comments

Comments
 (0)