@@ -9,8 +9,8 @@ title = "POJOs"
99
1010## POJOs - Plain Old Java Objects
1111
12- The 3.5 release of the driver adds POJO support via the [ ` PojoCodec ` ] ({{<apiref "org/bson/codecs/pojo/PojoCodec .html">}}), which allows for
13- direct serialization of POJOs and Java Beans to and from BSON. Internally, each ` PojoCodec ` utilizes a
12+ The 3.5 release of the driver adds POJO support via the [ ` PojoCodecProvider ` ] ({{<apiref "org/bson/codecs/pojo/PojoCodecProvider .html">}}),
13+ which allows for direct serialization of POJOs and Java Beans to and from BSON. Internally, the ` Codec ` for each POJO utilizes a
1414[ ` ClassModel ` ] ({{<apiref "org/bson/codecs/pojo/ClassModel.html">}}) instance to store metadata about how the POJO should be serialized.
1515
1616A ` ClassModel ` for a POJO includes:
@@ -43,7 +43,7 @@ ClassModels are built using the [`ClassModelBuilder`]({{<apiref "org/bson/codecs
4343 the [ ` ClassModel.builder(clazz) ` ] ({{<apiref "org/bson/codecs/pojo/ClassModel.html#builder-java.lang.Class-">}}) method. The builder
4444 initially uses reflection to create the required metadata.
4545
46- ` PojoCodec ` instances are created by the [ ` PojoCodecProvider ` ] ({{<apiref "org/bson/codecs/pojo/PojoCodecProvider.html">}}) which is a
46+ POJO ` Codec ` instances are created by the [ ` PojoCodecProvider ` ] ({{<apiref "org/bson/codecs/pojo/PojoCodecProvider.html">}}) which is a
4747` CodecProvider ` . CodecProviders are used by the ` CodecRegistry ` to find the correct ` Codec ` for any given class.
4848
4949{{% note class="important" %}}
@@ -58,8 +58,7 @@ encoded and decoded.
5858## POJO support
5959
6060Automatic POJO support can be provided by setting ` PojoCodecProvider.Builder#automatic(true) ` , once built the ` PojoCodecProvider ` will
61- automatically create a ` PojoCodec ` for any class that contains at least one serializable or deserializable
62- property.
61+ automatically create a POJO ` Codec ` for any class that contains at least one serializable or deserializable property.
6362
6463The entry point for customisable POJO support is the ` PojoCodecProvider ` . New instances can be created via the
6564[ ` PojoCodecProvider.builder() ` ] ({{<apiref "org/bson/codecs/pojo/PojoCodecProvider.html#builder">}}) method. The ` builder ` allows users to
@@ -70,8 +69,8 @@ register any combination of:
7069 * ` ClassModel ` instances which allow fine grained control over how a POJO is encoded and decoded.
7170
7271The ` builder ` also allows the user to register default [ Conventions] ( #conventions ) for any POJOs that are automatically mapped, either
73- the individual POJO classes or POJOs found from registered packages. The ` PojoCodecProvider ` will lookup PojoCodecs and return the first
74- that matches the POJO class:
72+ the individual POJO classes or POJOs found from registered packages. The ` PojoCodecProvider ` will lookup POJO ` Codec ` instances and return
73+ the first that matches the POJO class:
7574
7675 * Registered ClassModels
7776 * Registered POJO classes
@@ -96,14 +95,14 @@ CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), from
9695{{% note class="tip" %}}
9796In general only one instance of a ` PojoCodecProvider ` should be created.
9897
99- This is because each ` PojoCodecProvider ` instance contains a look up table for discriminator names. If multiple PojoCodecProviders are
98+ This is because each ` PojoCodecProvider ` instance contains a look up table for discriminator names. If multiple ` PojoCodecProvider ` s are
10099used, care should be taken to ensure that each provider contains a holistic view of POJO classes, otherwise discriminator lookups can fail.
101100Alternatively, using the full class name as the discriminator value will ensure successful POJO lookups.
102101{{% /note %}}
103102
104103## Default configuration
105104
106- By default the ` PojoCodec ` will not store ` null ` values or a discriminator when converting a POJO to BSON.
105+ By default the POJO ` Codec ` will not store ` null ` values or a discriminator when converting a POJO to BSON.
107106
108107Take the following ` Person ` class:
109108
@@ -195,8 +194,8 @@ public final class Tree extends GenericTree<Integer, String> {
195194The ` Tree ` POJO is serializable because it doesn't have any unknown type parameters. The ` left ` , ` right ` and ` genericClass ` properties are
196195all serializable because they are bound to the concrete types ` Integer ` , ` String ` and ` Long ` .
197196
198- On their own, instances of ` GenericTree ` or ` GenericClass ` are not serializable by the ` PojoCodec ` . This is because the runtime type parameter
199- information is erased by the JVM, and the type parameters cannot be specialized accurately.
197+ On their own, instances of ` GenericTree ` or ` GenericClass ` are not serializable by the POJO ` Codec ` . This is because the runtime type
198+ parameter information is erased by the JVM, and the type parameters cannot be specialized accurately.
200199
201200The 3.6 release of the driver further improves generic support with the addition of PropertyCodecProviders. The ` PropertyCodecProvider ` API
202201allows type-safe support of container types by providing concrete type parameters for the generic types as declared in the POJO.
@@ -273,8 +272,8 @@ public class Person {
273272
274273### Enum support
275274
276- Enums are fully supported. The ` PojoCodec ` uses the name of the enum constant as the property value. This is then converted back into an Enum
277- value by the codec using the static ` Enum.valueOf ` method.
275+ Enums are fully supported. The POJO ` Codec ` uses the name of the enum constant as the property value. This is then converted back into an
276+ Enum value by the codec using the static ` Enum.valueOf ` method.
278277
279278Take the following example:
280279
@@ -427,7 +426,7 @@ CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), from
427426
428427### Supporting POJOs without no args constructors
429428
430- By default PojoCodecs work with POJOs that have an empty, no arguments, constructor. POJOs with alternative constructors are supported
429+ By default a POJO ` Codec ` works with POJOs that have an empty, no arguments, constructor. POJOs with alternative constructors are supported
431430via the ` ANNOTATION_CONVENTION ` and the ` @BsonCreator ` annotation. Any parameters for the creator constructor should be annotated with the
432431` @BsonProperty ` annotation. Below is an example of a ` Person ` POJO that contains final fields that are set via the annotated constructor:
433432
0 commit comments