title: List of objects of derived types and JSON serializer
body: <p>In my application I have an abstract class <code>Block</code> which is a superclass for two concrete classes: <code>OperationBlock</code> and <code>DecisionBlock</code>.</p>
  <pre><code>abstract class Block
      {
          public abstract void Draw(Graphics graphics);
      }
  </code></pre>
  <p>For the sake of an example, here's a part of the <code>DecisionBlock</code> class:</p>
  <pre><code>class DecisionBlock : Block
      {
          [JsonInclude] private int x;
          [JsonInclude] private int y;
          [JsonInclude] private Point[] vertices;
          public DecisionBlock(int x, int y)
          {
              this.x = x;
              this.y = y;
              vertices = new Point[]
              {
                  new Point(x, y),
                  new Point(x + 50, y + 50),
                  new Point(x + 100, y),
                  new Point(x + 50, y - 50)
              };
          }
          // Draw() method, etc ...
      }
  </code></pre>
  <p>I store the <code>Block</code> objects in a list <code>List&lt;Block&gt; blocksList</code>. At one point, I want to save all the data about <code>Block</code>s in a file. The method responsible for saving the list to a file looks like that:</p>
  <pre><code>var options = new JsonSerializerOptions
  {
      IncludeFields = true,
  };
  string jsonString = JsonSerializer.Serialize(blocksList, options);
  File.WriteAllText(&quot;save.dat&quot;, jsonString);
  </code></pre>
  <p>After instantiating three <code>Block</code> objects, adding them to the list, and calling the above method, the contents of the <code>save.dat</code> file are</p>
  <pre><code>[{},{},{}]
  </code></pre>
  <p>(i.e. all the fields are apparently invisible to the serializer). I suspect that the serializer cannot handle polymorphism properly and what <em>really</em> gets serialized is the abstract <code>Block</code> class. Is there any way to fix this? Or do I have to forsake using JSON serialization altogether and save everything manually?</p>