[CSHARP-2041] EnumRepresentationConvention does not apply to arrays Created: 21/Sep/17 Updated: 27/Oct/23 Resolved: 25/Sep/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Configuration, Serialization |
| Affects Version/s: | 2.2.4, 2.3, 2.4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Nauck | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Hello, my goal is to store all enum types as string in MongoDB instead of the default int storage. I'm using the following code:
This code is executed before the first usage of MongoClient But looks like this setting is completely ignored. Any ideas? |
| Comments |
| Comment by Robert Stam [ 25/Sep/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Note that conventions like EnumRepresentationConvention are only used when building a BsonClasMap, and apply to members of type E, not to all values of type E. As written, this convention does not apply to members of type E[] (like Es). To serialize arrays of E as strings you would need a separate convention that applies to members of type E[]. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Nauck [ 25/Sep/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here is the code to reproduce:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 21/Sep/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I am unable to reproduce this. I used the following program:
And verified that the proper enum representation was used by inspecting the collection using the MongoDB shell:
Do you have a different scenario that can be used to reproduce what you are seeing? |