The Json.Net `JsonSerializer` uses at least `JsonConverterAttribute`, `IConverter` implementations, and built-in and CLR conversions to determine which `JsonValue` matches a provided object. The lower-level `BsonWriter` accepts only a `JsonArray` or `JsonObject` at the top level of a document due to BSON format restrictions. When the discovered conversions result in something else (a `JsonPrimitive` or `null`), the `BsonWriter` throws a `JsonWriterException`.
Our `BsonMediaTypeFormatter` attempts to avoid the above exceptions using an `IsSimpleType()` method which is based on `TypeDescriptor` and that class' idea of whether a value may be converted to a `string`. This determination does not align with what Json.Net actually does (as summarized above). I haven't found a top-level type which will see the exception but these cases definitely exist.
My expectation is types with attributes `TypeDescriptor` understands but Json.Net does not will cause the BSON formatter to use its workaround when it's not necessary. The opposite case (Json.Net conversions `TypeDescriptor` isn't aware of) should lead to `JsonWriterException`.
Comments: No input from Json.NET yet. Moving to 5.2 Preview.
Our `BsonMediaTypeFormatter` attempts to avoid the above exceptions using an `IsSimpleType()` method which is based on `TypeDescriptor` and that class' idea of whether a value may be converted to a `string`. This determination does not align with what Json.Net actually does (as summarized above). I haven't found a top-level type which will see the exception but these cases definitely exist.
My expectation is types with attributes `TypeDescriptor` understands but Json.Net does not will cause the BSON formatter to use its workaround when it's not necessary. The opposite case (Json.Net conversions `TypeDescriptor` isn't aware of) should lead to `JsonWriterException`.
Comments: No input from Json.NET yet. Moving to 5.2 Preview.