parent
7c485f2305
commit
e20339e60a
10 changed files with 151 additions and 44 deletions
@ -0,0 +1,22 @@ |
|||||||
|
using System.Reflection; |
||||||
|
using Newtonsoft.Json; |
||||||
|
using Newtonsoft.Json.Serialization; |
||||||
|
|
||||||
|
namespace SparkClient.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; |
||||||
|
} |
||||||
|
} |
||||||
Binary file not shown.
Loading…
Reference in new issue