How to set default value as guid when field is empty during deserialization

I am trying to pull records from the server via webservice, and in my model I have a parameter named public String mId {get;set;}, and my JSON structure looks like this

{  "name":"Jhon",  "mId":"",  "address":"55 jump street" }

Now, when mIdempty, I want to generate a new one GUIDfor this field, while json deserializing with Newton JSON, since [DefaultValue("")]it only accepts a constant value, I cannot use Guid.NewGuid()there

+4
source share
1 answer

This is not what it is used for DefaultValue. To add a default value:

string mId { get; set; } = Guid.NewGuid()
+3
source

Source: https://habr.com/ru/post/1675995/


All Articles