[CLOSED] An empty string in a property with ClientConfig attribute not serialized

  1. #1

    [CLOSED] An empty string in a property with ClientConfig attribute not serialized

    Hello,

    Let's say I have a class as follows:

    class BaseSettingTreeNode : TreeNode
    {
        public BaseSettingTreeNode()
        {
        }
    
        [ClientConfig]
        public string Test {get; set;}
    }
    When I serialize a tree nodes the following way:

    TreeNodeCollection nodes = new TreeNodeCollection( false );
     nodes.Add(new BaseSettingTreeNode()
     {
         Test = string.Empty
     });
    var json =  nodes.ToJson();

    the Test property is not serialized at all and the resulting JSON is just "[{}]", which results in 'undefined' in JavaScript. I believe it should be "[{test:""}]". When a null value or any other non-empty string value is assigned to the Test property, it is serialized properly as "[{test:null}]" or "[{test:"test"}]".


    Regards,
    Tadeusz
  2. #2

    RE: [CLOSED] An empty string in a property with ClientConfig attribute not serialized

    Hi,

    You need to define default value atrribute for property (if property equals default value then property will not be serialized)


    Empty string will not be serialized
    DefaultValue("")

    Null string will not be serialized
    DefaultValue(null)

Similar Threads

  1. ClientConfig Attribute
    By PerfectElement in forum 1.x Help
    Replies: 6
    Last Post: Nov 11, 2011, 4:50 PM
  2. Replies: 1
    Last Post: Feb 28, 2011, 8:13 AM
  3. Replies: 2
    Last Post: Feb 27, 2011, 3:33 PM
  4. Replies: 1
    Last Post: Jan 13, 2011, 11:23 AM
  5. Replies: 3
    Last Post: Nov 12, 2008, 5:16 AM

Posting Permissions