hwcverwe
hwcverwe

Reputation: 5367

Exclude properties from serialization to Json string - DynamicJson

I have an object which need to be serialized.
Object to serialize:

public class Setting
{
    // Exclude from serialization
    private SettingInfo _key;
    public SettingInfo Key
    {
        get { return _key; }
        set 
        { 
            _key = value;
            Key_Id = _key == null ? 0 : _key.Id;
        }
    }

    // Need to be serialized
    public int Key_Id { get; set; }
    public string Value { get; set; }
}

Question:
Is it possible to exclude the SettingInfo object (Property Key) from serialization using DynamicJson?

Upvotes: 0

Views: 444

Answers (1)

Krzysztof
Krzysztof

Reputation: 16150

Usually you would do it with property attribute, but in this lib there are no attributes. Below is not very beautiful, but working solution.

var r = DynamicJson.Serialize(s);
DynamicJson tt = DynamicJson.Parse(r);
tt.Delete("Key");

r = tt.ToString();

Upvotes: 1

Related Questions