Runtime: Suggestion: Give warning/error if model attribute will have no effect such as Newtonsoft [JsonIgnore] Being Replaced in .NET Core 3.0

Created on 9 Oct 2019  路  3Comments  路  Source: dotnet/runtime

Is it possible to consider giving a warning if a Model Attribute is not valid?

An example is that [JsonIgnore] used using Newtonsoft.Json; in .NET Core 2.2 but in .NET Core 3.0 this was removed so the [JsonIgnore] attribute then had no effect but generates no errors or warnings.

The fix is to switch the using statement to:

using System.Text.Json;
using System.Text.Json.Serialization;

However it would be good if the serializer could support attributes to check validity helping to track down issues and save having to debug the compiled program.

area-System.Text.Json

Most helpful comment

Instead of a warning, could we consider supporting this attribute by name?

All 3 comments

Instead of a warning, could we consider supporting this attribute by name?

@layomia / @steveharter this is similar to the Newtonsof.JSON interpretation/compatibility that others have been asking for.

This gives the serializer more work to do on start up, which is an area we are focused on optimizing. Developers should examine all attributes and options if migrating to System.Text.Json.

Was this page helpful?
0 / 5 - 0 ratings