[CSHARP-4758] Modify BsonClassMapSerializer to handle properties that are grouped in a nested document Created: 17/Aug/23  Updated: 21/Aug/23

Status: Backlog
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.21.0
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Robert Stam Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-4757 Modify BsonSerializationInfo to handl... Closed

 Description   

In some cases it can be advantageous to group several properties under a nested document in the serialized form.

For example, the class:

public class OrderItem
{
    public int OrderId { get; set; }
    public int ProductId { get; set; }
    public int Quantity { get; set; }
}

might need to be serialized as:

{
    _id :
    {
        OrderId : 1,
        ProductId : 2
    },
    Quantity : 3
}

While this serialization format could also be achieved by declaring a custom POCO to hold the OrderId/ProductId pair, there are cases where we might want the components of a compound primary key to appear at the top level in the POCO while being grouped together in a nested `_id` element in the serialized form.

We would like to support this option when using the `BsonClassMapSerializer`. This feature requires changes to the `BsonClassMapSerializer`, as well as adding code and attribute based ways to configure this.


Generated at Wed Feb 07 21:49:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.