Lets say I have a class which has a property with corresponding ShouldSerialize#Property# set to false but occasionally I want it to be serialized.
When using Newtonsofts serializer this is quite straight forward by setting IgnoreShouldSerializeMembers to true in the DefaultContractResolver however I have not found an equivalent way of doing so in ServiceStack.
Am I stuck with changing the ShouldSerialize property value by reflection or is there perhaps a more convenient way of getting around the issue?
public class Foo
{
public string Id { get; set; } = "1";
public string Value { get; set; }
public bool ShouldSerializeId() => false;
}
Newtonsoft:
JsonConvert.SerializeObject(foo, new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
IgnoreShouldSerializeMembers = true
}
});