This project is read-only.

Please support Bson if you are implementing Json.NET in WebApi.

Topics: ASP.NET Web API
Jun 15, 2012 at 1:35 AM
Edited Jun 15, 2012 at 1:37 AM

I'm so happy to see Json.NET being baked into Web API, however, I still have to write my own custom MediaTypeFormatter to support Bson.  Json.NET supports this very easily using the same JsonSerializer.

Something like:

if (contentHeaders.ContentType.MediaType.Equals("application/bson"StringComparison.InvariantCultureIgnoreCase))
    // using new BsonWriter(stream) ...
Serialize(bsonWriter, ...) } else {
// using new JsonTextWriter(new StreamWriter(stream)) ...
Serialize(jsonTextWriter, ... }

 static void Serialize(JsonWriter jsonWriter, Object instance, JsonSerializerSettings serializerSettings)

Bson uses the same JsonSerializer / JsonSerializerSettings.  BsonReader and BsonWriter inherit from JsonReader JsonWriter respectively.

Please consider adding this support. Thanks!

Jun 15, 2012 at 6:03 AM

Not a bad idea -- please log an issue so that we can track.



Jun 15, 2012 at 3:20 PM

Thanks for the consideration Henrik.  I've created an issue: