-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 0.9
-
Component/s: None
-
None
-
Environment:Win 7
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(
BsonWriter bsonWriter,
object obj,
BsonMemberMap memberMap
) {
var value = memberMap.Getter(obj);
if (value == null && memberMap.IgnoreIfNull)
if (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && value.Equals(memberMap.DefaultValue))
{ return; // don't serialize default value }