Runtime: Add Bson integration

Created on 23 Dec 2019  路  3Comments  路  Source: dotnet/runtime

Add Bson integration to a namespace like System.Text.Bson or System.Text.Json.Bson

area-System.Text.Json enhancement

All 3 comments

Can you provide more details around your scenario, use case, and what types of APIs/capabilities you expect?

If you could share some requirements, and API shape along with sample code you would write on top, that would help motivate the feature.

I am currently using Newtonsoft.Json to serialize / deserialize bson,
I'd like to use it when I want to serialize to a stream or a return value using an object or an instance and deserialize byte array to return an object or an instance

void Save<TData>(string file, TData data)
{
    using var stream = File.OpenWrite(data);
    BsonSerializer.Serialize<TData>(stream, data); // Can be async
}
void Save<TData>(string file, TData data)
{
    var data = BsonSerializer.Serialize<TData>(data);
    File.WriteAllBytes(file, data);
}



md5-82a793b316c425db07d8e79250ba8a1c



```csharp
TData Read<TData>(string file)
{
    var data = File.ReadAllBytes(file);
    return BsonSerializer.Deserialize<TData>(data);
}

Closing - we don't have plans to support this format at the moment.

Was this page helpful?
0 / 5 - 0 ratings