Skip to content

Commit 727daeb

Browse files
committed
pojo
1 parent c4e2934 commit 727daeb

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

source/connection/connect.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Connect to MongoDB
99
:backlinks: none
1010
:depth: 1
1111
:class: singlecol
12-
12+
1313
.. facet::
1414
:name: genre
1515
:values: reference
@@ -206,7 +206,7 @@ class. Select the tab that corresponds to your preferred class.
206206
.build();
207207
MongoClient mongoClient = MongoClients.create(settings);
208208

209-
Frequently Asked Questions
209+
ked Questions
210210
--------------------------
211211

212212
This section answers questions that may arise when
@@ -217,7 +217,7 @@ Why are there two types of ``MongoClient`` in the Java driver?
217217

218218
There are two types of ``MongoClient`` because we wanted a cleaner API
219219
for new users that didn't have the confusion of including multiple CRUD
220-
APIs. We wanted to ensure that the new CRUD API was available in a Java
220+
Frequently AsAPIs. We wanted to ensure that the new CRUD API was available in a Java
221221
package structure that would work well with Java module support
222222
introduced in Java 9.
223223

source/data-formats/document-data-format-pojo.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,48 @@ see the following API documentation:
206206
- `getDefaultCodecRegistry() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html?is-external=true#getDefaultCodecRegistry()>`__
207207
- `fromProviders() <{+api+}/apidocs/bson/org/bson/codecs/configuration/CodecRegistries.html#fromProviders(org.bson.codecs.configuration.CodecProvider...)>`__
208208

209+
Frequently Asked Questions
210+
--------------------------
211+
212+
This section answers questions that may arise when storing
213+
POJOs in MongoDB.
214+
215+
Do I have to specify an ID field value myself?
216+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217+
218+
No, the ``PojoCodecProvider`` automatically generates an ObjectId.
219+
220+
Can the ID field be a compound key?
221+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222+
223+
Yes. For an example of this, see `our implementation <https://github.com/niccottrell/mongo-java-tests/blob/master/src/test/PojoCompoundIdTest.java>`__
224+
in Github.
225+
226+
Can I use polymorphism in a POJO accessor?
227+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228+
229+
Yes, by using a discriminator. For more information, see the :ref:`Discriminators
230+
<pojo-discriminators>` section of the POJO Customization guide.
231+
232+
Can I mix private, protected, and public setters and getters?
233+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234+
235+
No. The native POJO codec assumes that getters and setters have the same
236+
modifiers for each field.
237+
238+
For example, the following methods throws an exception during encoding:
239+
240+
.. code-block:: java
241+
242+
private String getField();
243+
public String setField(String x);
244+
245+
How do I fix: "org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class X."?
246+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247+
248+
This exception means you must register a codec for the class since
249+
none exist.
250+
209251
Summary
210252
-------
211253

source/data-formats/pojo-customization.txt

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ see the following API Documentation:
749749

750750
For more information about generics and type parameters, see the
751751
`Java language guide on Invoking and Instantiating a Generic Type <https://docs.oracle.com/javase/tutorial/java/generics/types.html#instantiation>`__.
752-
752+
753753
Enum Type Support
754754
^^^^^^^^^^^^^^^^^
755755

@@ -759,31 +759,14 @@ a codec for ``enum`` types if you need one, such as the one in the default
759759
codec registry.
760760

761761
See the documentation on the :ref:`default codec registry <codecs-default-codec-registry>`
762-
For more information about how to register the codecs it includes.
762+
for more information about how to register the codecs it includes.
763763

764764
Frequently Asked Questions
765765
--------------------------
766766

767767
This section answers questions that may arise when defining
768768
data conversion logic.
769769

770-
Do I have to specify an ID field value myself?
771-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
772-
773-
No, the ``PojoCodecProvider`` automatically generates an ObjectId.
774-
775-
Can the ID field be a compound key?
776-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
777-
778-
Yes. For an example of this, see `our implementation <https://github.com/niccottrell/mongo-java-tests/blob/master/src/test/PojoCompoundIdTest.java>`__
779-
in Github.
780-
781-
Can I use polymorphism in a POJO accessor?
782-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
783-
784-
Yes, by using a discriminator. For more information, see the :ref:`Discriminators
785-
<pojo-discriminators>` section.
786-
787770
Can I control serialization of ``LocalDate``?
788771
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
789772

@@ -812,25 +795,6 @@ You can configure the ``PojoCodecProvider`` to use the
812795
``SET_PRIVATE_FIELDS_CONVENTION``, which sets a private field through
813796
reflection if no public setter is available.
814797

815-
Can I mix private, protected, and public setters and getters?
816-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
817-
818-
No. The native POJO codec assumes that getters and setters have the same
819-
modifiers for each field.
820-
821-
For example, the following methods throws an exception during encoding:
822-
823-
.. code-block:: java
824-
825-
private String getField();
826-
public String setField(String x);
827-
828-
How do I fix: "org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class X."?
829-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
830-
831-
This exception means you must register a codec for the class since
832-
none exist.
833-
834798
How do I specify the collection name for a particular POJO class? Is there an annotation?
835799
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
836800

0 commit comments

Comments
 (0)