0

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?

  • I am using DynamicJson
  • Current result: (which contains the serialized Key property)
    {"Key":{"Id":20,"Type":"System.String","Name":"ExampleSetting"},
    "Key_Id":20,
    "Value":"New Value"}
  • Requested result: {"Key_Id":20,"Value":"New Value"}

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.