[CSHARP-308] Support serialization options for Array and Dictionary values Created: 22/Aug/11  Updated: 02/Apr/15  Resolved: 02/May/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.3.1, 1.4.2
Fix Version/s: 1.4, 1.5

Type: New Feature Priority: Minor - P4
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-284 Add a way to provide serialization at... Closed

 Description   

Support serialization options for Array and Dictionary values. For example, given the types:

[Flags]
public enum F { ... }
 
public class C {
    public ObjectId Id;
    public List<F> A;
    public Dictionary<string, F> D;
}

we want to be able to apply serialization options to the F values to serialize them as strings (this is just one example, F could be any other type).



 Comments   
Comment by Robert Stam [ 02/May/12 ]

Additional work to handle the edge case of deserializing string items that were serialized as ObjectIds.

Comment by Robert Stam [ 01/May/12 ]

Looks like this was implemented for Serialize methods but not for Deserialize methods.

Comment by Robert Stam [ 15/Mar/12 ]

Finished adding support for itemSerializationOptions to generic and legacy versions of EnumerableSerializer, QueueSerializer and StackSerializer.

Comment by Robert Stam [ 15/Mar/12 ]

This is mostly implemented, but I won't close the ticket just yet.

In the sample code from the description, the enums could be serialized as string as follows:

[Flags]
public enum F { ... }
 
public class C {
    public ObjectId Id;
    [BsonRepresentation(BsonType.String)] // applies to the items in A instead of to A itself
    public List<F> A;
    [BsonRepresentation(BsonType.String)] // applies to the items (values) in D instead of to D itself
    public Dictionary<string, F> D;
}

The strategy is that attributes that don't make sense for the container apply instead to the items.

I'm leaving the ticket open a little longer because there are still some obscure collection types that don't yet support this (Stacks, Queues, etc...).

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