[CSHARP-95] Improve how DataContractJsonSerializer serializes ObjectIds Created: 10/Nov/10  Updated: 02/Apr/15  Resolved: 19/Nov/10

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 0.9
Fix Version/s: 0.9

Type: Improvement Priority: Minor - P4
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:

Any



 Description   

If you have a class Decorated with DataContractAttribute, with a property of type ObjectId decorated with a DataMemberAttribute, and you return it as a response from a call through webHttpBinding (JSON), the property gets serialized as such:

"Id":

{"__type":"ObjectId:#MongoDB.Bson","machinePidIncrement":-5429670957678174237,"timestamp":1289430110}

I think it would make more sense if ObjectId (and BsonObjectId) would be custom serialized to just 4cdb247be076000000001f86 or maybe ObjectId('4cdb247be076000000001f86') for interoptability purposes.



 Comments   
Comment by Robert Stam [ 19/Nov/10 ]

Changed the internal representation of an ObjectId from (int, long) to (int, int, short, int). While it does take two extra bytes it makes everything a lot simpler and also makes it possible to serialize an ObjectId using the DataContractJsonSerializer without running into 64 bit overflow problems in a JavaScript client.

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