Reputation: 5367
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
?
DynamicJson
Key
property){"Key":{"Id":20,"Type":"System.String","Name":"ExampleSetting"},
"Key_Id":20,
"Value":"New Value"}
{"Key_Id":20,"Value":"New Value"}
Upvotes: 0
Views: 444
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