I am making a PUT call to update user using url https://myWebsite.com/users with json body
[{
"Name" : "John",
}]
As I have not passed the "Status" attribute in json body, it is set as false by default as false is the default value of the Boolean data type.
But, I need to set it to true as the default value if the property is not passed in the json when making the API call.
I tried to use OnDeserializing attribute as below:
[OnDeserializing]
void BeforeDeserialization(StreamingContext ctx)
{
this.Status = true;
}
but it was not working.
Model looks like below:
[DataContract (Namespace = "mynamespace")]
public class User
{
[DataMember]
public string Name { get; set; }
[DataMember]
public bool Status { get; set; }
}
Please help me with the issue.