Newtonsoft.Json
Newtonsoft.Json copied to clipboard
Feature request: support System.Text.Json attribute annotations
We have a library with types that we'd like to work with both Newtonsoft.Json and System.Text.Json. Today, this requires specifying duplicate attributes on all properties for things like default value handling.
It would be nice if Newtonsoft.Json would pick up and use System.Text.Json annotations when available (at least when targeting newer versions of .NET Core) and respect those.
I think there is already some precedent for this type of behavior with the support for DataContract attributes.
Especially for the JsonPropertyName-Annotation. I also maintain a library which I want to migrate to System.Text.Json or be able to be compatible. This library only contains DTO-Objects and no other features are used.
@JamesNK Is there any possibility of this happening in the future? Maybe an optional Newtonsoft.Json.Compatibility assembly that has a converter with the System.Text.Json reference? I'm running into the same problem that I can't provide backwards compatibility to my object library because it is using the built-in .NET attributes by default.
I just shipped support for this in the EasyAF.NewtonsoftJson.Compatibility package on NuGet. Just add the SystemTextJsonContractResolver to your JsonSerializerSettings instance and it just works.