2015년 1월 9일 금요일

The parsing error from BsonDocument to JsonReader

I have to work the MongoDB C# Driver and Json.Net.

This sources installed from Nuget.

And i made a function of deserializer.  It is as follows:

public static T ConvertTo<T>(this JsonSerializer serializer, BsonDocument bson)
{
    using (var jsonReader = new JTokenReader(JToken.Parse(bson.ToJson())))
    {
        jsonReader.DateTimeZoneHandling = DateTimeZoneHandling.Local;
        var result = serializer.Deserialize<T>(jsonReader);
        return result;
    }
}

But.. The problem of parsing error occurs when BsonDocument to JsonReader coverting.

"_id" : ObjectId("54ab8b06d05efe1e5063941f") => String
"date" : ISODate("2015-01-06T07:13:09.993Z") => DateTime

ObjectId and ISODate types are not converted.

I would like to know a solution for this.


댓글 없음:

댓글 쓰기