System.Web.Script.Serialization.JavaScriptSerializer - prevent serializing a property

Issue:

Use the .Net JavaScriptSerializer  to serialize an object but due to circular references need to prevent from those properties from being serialized.

Solution:

In order to ignore certain properties from getting serialized, simply add the ScriptIgnoreAttribute attribute to the property:

        [ScriptIgnore]
        public virtual MyClassCausingCircularRefError MyProperty
        {
            get { return _privateField; }
        }

Print | posted @ Friday, September 2, 2011 10:28 AM

Comments on this entry:

No comments posted yet.

Post A Comment
Title:
Name:
Email:
Comment:
Verification: