[CSHARP-133] [BsonDefaultValue(null, SerializeDefaultValue = false)] doesn't work as expected Created: 13/Dec/10 Updated: 02/Apr/15 Resolved: 13/Dec/10 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 0.9 |
| Fix Version/s: | 1.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Ian Mercer | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Win 7 |
||
| Description |
|
If I have an object with a null on it for a property that is marked "[BsonDefaultValue(null, SerializeDefaultValue = false)]", I'd expect that no value would get written to the database. But what happens is that the test code to decide whether null == null blows up because of the way it is written. Looking at the code I can see that I should have used [BsonIgnoreIfNull] but why isn't [BsonIgnoreIfNull] equivalent to [BsonDefaultValue(null, SerializeDefaultValue = false)]? Suggest that with a small tweak this code could be made to work whichever way a user chooses to specify that null values are the default and are to be ignored. private void SerializeMember( if (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && value.Equals(memberMap.DefaultValue)) { return; // don't serialize default value } |
| Comments |
| Comment by Robert Stam [ 13/Dec/10 ] |
|
Fixed. Thanks for finding this. |