Analyzer/Code fix idea: JsonConverters applied to properties implementing a collection #85540
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Text.Json
code-analyzer
Marks an issue that suggests a Roslyn analyzer
Milestone
Per #85479 and #54189 the preferred approach to apply a custom JsonConverter is to apply the converter type to the type being converted so that it's used whether (de)serializing a single entity or a collection of entities using that converter.
Having not realized that, I would propose that an analyzer (potentially with a code fix) be added that identifies when
[JsonConverter]
has been applied to a property that itself represents a collection of the type the JsonConverter is typed for since this will actually throw at runtime. The code fix should move the[JsonConverter]
attribute from its position on any various properties to the type definition itself (when available in the same assembly) so it's applied consistently whether to a single or collection of the type.Thank you for the consideration!
The text was updated successfully, but these errors were encountered: