You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When serializing classes inheriting from ObservableValidator using System.Text.Json the 'HasErrors' property also gets serialized.
To ensure a clean JSON output, it would be beneficial to add the [JsonIgnore] attribute to the 'HasErrors' property.
As this property has no state there shouldn't be any disadvantages having it ignored from serialization.
namespaceCommunityToolkit.Mvvm.ComponentModel;publicabstractclassObservableValidator:ObservableObject,INotifyDataErrorInfo{[JsonIgnore]<<<Addedattribute[Display(AutoGenerateField=false)]
public boolHasErrors=>this.totalErrors>0;}
Regression
No response
Steps to reproduce
Create a class inheriting from ObservableValidator
Use System.Text.Json to serialize the class
The 'HasErrors' property is included in the resulting JSON
Expected behavior
As this property has no state it should be ignored from serialization.
Workaround
There is a workaround using a custom DefaultJsonTypeInfoResolver to exclude the property from the serialization.
publicsealedclassIgnoreHasErrorsTypeResolver:DefaultJsonTypeInfoResolver{publicoverrideJsonTypeInfoGetTypeInfo(Typetype,JsonSerializerOptionsoptions){JsonTypeInfojsonTypeInfo=base.GetTypeInfo(type,options);JsonPropertyInfo?propToRemove=jsonTypeInfo.Properties.FirstOrDefault(prop =>prop.Nameisnameof(ObservableValidator.HasErrors));if(propToRemoveis not null)jsonTypeInfo.Properties.Remove(propToRemove);returnjsonTypeInfo;}}
IDE and version
VS 2022
IDE version
No response
Nuget packages
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.3.2
Additional context
No response
Help us help you
Yes, but only if others can assist
The text was updated successfully, but these errors were encountered:
Describe the bug
When serializing classes inheriting from ObservableValidator using System.Text.Json the 'HasErrors' property also gets serialized.
To ensure a clean JSON output, it would be beneficial to add the [JsonIgnore] attribute to the 'HasErrors' property.
As this property has no state there shouldn't be any disadvantages having it ignored from serialization.
Regression
No response
Steps to reproduce
Expected behavior
As this property has no state it should be ignored from serialization.
Workaround
There is a workaround using a custom DefaultJsonTypeInfoResolver to exclude the property from the serialization.
IDE and version
VS 2022
IDE version
No response
Nuget packages
Nuget package version(s)
8.3.2
Additional context
No response
Help us help you
Yes, but only if others can assist
The text was updated successfully, but these errors were encountered: