title: Serializing a protected property in a generic class with Json.NET
body: <p>I am trying to serialize a class that is made up of many variables all inheriting from <code>IMyDataType</code>. </p>
  
  <pre><code>public abstract class IMyDataType&lt;T&gt;
  {
      protected virtual T Data { get; set; }
      public abstract String ToString(String args = null);
      public abstract Boolean SetValue(T newValue);
      public abstract Boolean CheckValue(T newValue);
      public abstract T GetValue();
  }
  </code></pre>
  
  <p>For instance I might have a class <code>MyInteger</code></p>
  
  <pre><code>public class MyInteger : IMyDataType&lt;int&gt;
  {
      public int Min { get; protected set; }
      public int Max { get; protected set; }
      protected override int Data { get; set; }
  
      public MyInteger(int value)
      {
          Min = int.MinValue;
          Max = int.MaxValue;
          if (!SetValue(value))
              Data = 0;
      }
  
      public MyInteger(int min, int value, int max)
      {
          Min = min;
          Max = max;
          if (!SetValue(value))
              Data = 0;
      }
  
      public override Boolean SetValue(int newVal)
      {
          if (newVal &gt;= Min &amp;&amp; newVal &lt;= Max)
          {
              Data = newVal;
              return true;
          }
          return false;
      }
  
      public override Boolean CheckValue(int newVal)
      {
          return (newVal &gt;= Min &amp;&amp; newVal &lt;= Max);
      }
  
      public override int GetValue() { return Data; }
      public override String ToString(String args = null) { return Data.ToString(args); }
  }
  </code></pre>
  
  <p>Whenever I try to serialize a subclass of <code>IMyDataType</code> the variable <code>T Data</code> is never serialized, though <code>Min</code> and <code>Max</code> are. What do I need to do to get <code>T Data</code> to be serialized?</p>
  
  <p><strong>EDIT:</strong> Based on DotNetom's answer I changed the access modifier of <code>T Data</code> to public, which did allow it to be serialized. Though, there are reasons for it being protected. Is there any other means by which I could serialize it while keeping its access modifier intact?</p>