using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; namespace BrilliantSightClient.Model.Extension; public class DefaultValueContractResolver: DefaultContractResolver { protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.CreateProperty(member, memberSerialization); if (property.PropertyType.IsValueType && Nullable.GetUnderlyingType(property.PropertyType) == null) // 非可空类型 { property.DefaultValue = Activator.CreateInstance(property.PropertyType); property.DefaultValueHandling = DefaultValueHandling.Populate; } return property; } }