Ignore ShouldSerialize#PropertyName# at Serialization

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;


JsonConvert.SerializeObject(foo, new JsonSerializerSettings
            ContractResolver = new DefaultContractResolver
                IgnoreShouldSerializeMembers = true

In addition to ShouldSerialize{X} naming convention you can also use ShouldSerialize(fieldName) where you could use your own static bool? config to globally force non/serialization of all properties, e.g:

public bool? ShouldSerialize(string fieldName) =>
    MyConfig.ShouldSerializeMembers ?? DefaultBehavior(fieldName);