[CSHARP-97] Deserializing a BsonDocument to .net object should not throw FormatException if the document has extra properties. Created: 14/Nov/10 Updated: 02/Apr/15 Resolved: 14/Nov/10 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 0.7 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Justin Dearing | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
VS 2k8 Win7 |
||
| Description |
|
If I have a bson document with keys that do not map to properties in a .net object I am deserializing to, a FormatException is thrown. While I am returning more info than necessary over the wire (doing the mongo equivalent of SELECT * ) I think the code should still function. at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.DeserializeDocument(BsonReader bsonReader, Type nominalType) in D:\justin's projects\mongo-csharp\Bson\DefaultSerializer\BsonClassMapSerializer.cs:line 83 |
| Comments |
| Comment by Robert Stam [ 14/Nov/10 ] |
|
Works as designed. |
| Comment by Justin Dearing [ 14/Nov/10 ] |
|
Ok that works for me. You can close this, and thanks for pointing out the risks, |
| Comment by Robert Stam [ 14/Nov/10 ] |
|
You can always use [BsonIgnoreExtraElements] to deserialize documents with extra elements. This question is whether it is safe to ignore extra elements without your permission. I think it is not, as it can easily lead to data loss (for example, if you save the document back to the database). |