BSON-ObjectId

Mar 3, 2010 at 11:16 AM
Edited Mar 3, 2010 at 11:16 AM

Hi!

Do you plan on incorporating support for ObjectId (http://bsonspec.org/#/specification) in the writer so that it doesn't handle it as bytes?

//Daniel

Mar 3, 2010 at 2:32 PM

 

I have implemented the support for Oid in a personal branch. If you are interested in the code, please contact me. The implementation was done via creating "WriteOid" on the writer. I extended JToken, JsonToken, CalculateSize etc. to handle Oid.
I then decorate my class that represents Oid with a specific converter that calls this new WriiteOidValue instead.
//Daniel

I have implemented the support for Oid in a personal branch. If you are interested in the code, please respond. The implementation that I did was done via creating "WriteOid" on the writer. I extended JToken, JsonToken, CalculateSize etc. to handle Oid.

I then decorated my class (living outside Json.Net) that represents Oid with a specific converter that calls this new WriiteOidValue instead.

I bet that you have a nicer implementation for it, if not, I think it would be great to lift this code into the mainstream.

 

//Daniel

 

Coordinator
Mar 17, 2010 at 7:01 AM

Thanks for the code. I made a lot of changes but have added support for writing Object Ids.

http://json.codeplex.com/SourceControl/list/changesets

Let me know if that is what you're looking for.

Mar 17, 2010 at 7:43 AM

Downloading right now.....

Will let you now.

 

//Daniel

Mar 17, 2010 at 8:21 AM

It works. One question though. What if WriteObjectId is implemented also in the JsonWriter? It could handle it as a simple byte[].

 

//Daniel

Coordinator
Mar 17, 2010 at 8:42 AM
Edited Mar 17, 2010 at 8:43 AM

I don't want to add it to JsonWriter because an ObjectId is specific to BSON. Is there a reason why you would like it on JsonWriter?

Mar 17, 2010 at 8:56 AM
That's fair. And of course this could be handled in a specific converter. 

Sent from my iPhone

17 mar 2010 kl. 09.42 skrev JamesNK <notifications@codeplex.com>:

From: JamesNK

I don't want to add it to JsonWriter because an ObjectId is specific to BSON.

Mar 19, 2010 at 10:18 PM

So, I'm sitting and adding support for the BsonWriter to handle Regex's. One thing that seams a bit odd is that you handle ObjectId's as Raw. Even if it just is raw bytes, why not explicitly handle it as a ObjectId type? It seems especially odd in the GetTypeNumber-func, where JTokenType.Raw is mapped to BsonType.Oid

//Daniel