title: C# JSON Deserialization System.NotSupportedException
body: <p>I have been working on a project which needs to save and load data through a JSON file. This JSON file includes various lists of other objects. When I go ahead and deserialize the file, however, this happens:</p>
  <blockquote>
  <p>System.NotSupportedException: Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported.</p>
  </blockquote>
  <p>The code that takes care of deserializing is as follows:</p>
  <pre><code>        public void LoadFromJson() {
  
          int userCount = File.ReadAllLines(folder + &quot;/users&quot;).Length;
          int shopCount = File.ReadAllLines(folder + &quot;/shops&quot;).Length;
          using (FileStream fileUsers = File.Open(folder + &quot;/users&quot;, FileMode.Open, FileAccess.Read)) {
              StreamReader srUser = new StreamReader(fileUsers);
              for(int i=0; i&lt;userCount; i++){
                  ListOfUsers.Add(JsonSerializer.Deserialize&lt;User&gt;(srUser.ReadLine()));
              }
              srUser.Close();
              fileUsers.Close();
          }  
  
          using (FileStream fileShops = File.Open(folder + &quot;/shops&quot;, FileMode.Open, FileAccess.Read)){
              StreamReader srShops = new StreamReader(fileShops);
              for(int i=0; i&lt;shopCount; i++){
                  ListOfShops.Add(JsonSerializer.Deserialize&lt;Shop&gt;(srShops.ReadLine()));
              }
              srShops.Close();
              fileShops.Close();
          }       
  
      }
  </code></pre>
  <p>Classes I'm trying to deserialize</p>
  <pre><code>    public abstract class Shop{
  
      public List&lt;Sellable&gt; ShopList { get; set; }
      public int TotalValue { get; set; }
      public string shopName { get; set; }
  
      public Shop(List&lt;Sellable&gt; list, string shopname){
          ShopList = list;
          shopName = shopname;
      }
  
      public abstract bool AddToShop(Sellable item);
      public abstract bool RemoveFromShop(string item);
      public abstract int GetValue(string name);
      public abstract string PrintShop();
  
  }
  
      public abstract class Furniture : Sellable{
      public int Space { get; set; }
      public Conditions Condition { get; set; }
      public Materials Material { get; set; }
  
      [JsonConstructorAttribute]
      public Furniture(int val, int spc, string nm, Conditions condition, Materials material) : base (val, nm){
          Space = spc;
          Condition = condition;
          Material = material;
      }
  
  }
  
      public abstract class Sellable{
      public int Value { get; set; }
      public string Name { get; set; }
  
      [JsonConstructorAttribute]
      public Sellable(int val, string name){
          Value = val;
          Name = name;
      }
  </code></pre>
  <p>JsonConverter</p>
  <pre><code>    public class SellableConverter : JsonConverter&lt;Sellable&gt;{ 
  
      public enum Type{
          Sellable,
          Furniture,
          Wearable,
  
      }
  
      public override Sellable Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options)
      {
          if (reader.TokenType != JsonTokenType.StartObject) throw new JsonException();
  
          if (!reader.Read()
                  || reader.TokenType != JsonTokenType.PropertyName
                  || reader.GetString() != &quot;Type&quot;) throw new JsonException();
  
          if (!reader.Read() || reader.TokenType != JsonTokenType.Number) throw new JsonException();
  
          Sellable baseClass;
          Type typeDiscriminator = (Type)reader.GetInt32();
          switch (typeDiscriminator)
          {
              case Type.Furniture:
                  if (!reader.Read() || reader.GetString() != &quot;TypeValue&quot;) throw new JsonException();
                  if (!reader.Read() || reader.TokenType != JsonTokenType.StartObject) throw new JsonException();
                  baseClass = (Furniture.Furniture)JsonSerializer.Deserialize(ref reader, typeof(Furniture.Furniture), options);
                  break;
              case Type.Wearable:
                  if (!reader.Read() || reader.GetString() != &quot;TypeValue&quot;) throw new JsonException();
                  if (!reader.Read() || reader.TokenType != JsonTokenType.StartObject) throw new JsonException();
                  baseClass = (Wearable)JsonSerializer.Deserialize(ref reader, typeof(Wearable), options);
                  break;
              case Type.Sellable:
                  if (!reader.Read() || reader.GetString() != &quot;TypeValue&quot;) throw new JsonException();
                  if (!reader.Read() || reader.TokenType != JsonTokenType.StartObject) throw new JsonException();
                  baseClass = (Sellable)JsonSerializer.Deserialize(ref reader, typeof(Sellable));
                  break;
              default:
                  throw new NotSupportedException();
          }
  
          if (!reader.Read() || reader.TokenType != JsonTokenType.EndObject) throw new JsonException();
  
          return baseClass;
      }
  
      public override void Write(Utf8JsonWriter writer, Sellable value, JsonSerializerOptions options)
      {
          writer.WriteStartObject();
  
          if (value is Furniture.Furniture derivedA)
          {
              writer.WriteNumber(&quot;TypeDiscriminator&quot;, (int)Type.Furniture);
              writer.WritePropertyName(&quot;TypeValue&quot;);
              JsonSerializer.Serialize(writer, derivedA, options);
          }
          else if (value is Wearable derivedB)
          {
              writer.WriteNumber(&quot;TypeDiscriminator&quot;, (int)Type.Wearable);
              writer.WritePropertyName(&quot;TypeValue&quot;);
              JsonSerializer.Serialize(writer, derivedB, options);
          }
          else if (value is Sellable baseClass)
          {
              writer.WriteNumber(&quot;TypeDiscriminator&quot;, (int)Type.Sellable);
              writer.WritePropertyName(&quot;TypeValue&quot;);
              JsonSerializer.Serialize(writer, baseClass);
          }
          else throw new NotSupportedException();
  
          writer.WriteEndObject();
      }
  }
  </code></pre>
  <p>SaveToJson method:</p>
  <pre><code>        public void SaveToJson(){
  
          FileStream fileUsers;
          FileStream fileShops;
  
          if(!(File.Exists(folder + &quot;/users&quot;))) fileUsers = File.Create(folder + &quot;/users&quot;);
          else fileUsers = File.OpenWrite(folder + &quot;/users&quot;);
          if(!(File.Exists(folder + &quot;/shops&quot;))) fileShops = File.Create(folder + &quot;/shops&quot;);
          else fileShops = File.OpenWrite(folder + &quot;/shops&quot;);
  
          StreamWriter srUser = new StreamWriter(fileUsers);
          StreamWriter srShop = new StreamWriter(fileShops);
  
          var serializeOptions = new JsonSerializerOptions();
          serializeOptions.Converters.Add(new SellableConverter());
  
          for(int i=0; i&lt;ListOfUsers.Count; i++){
              srUser.WriteLine(JsonSerializer.Serialize&lt;User&gt;(ListOfUsers[i]), serializeOptions);
              Console.WriteLine(&quot;Debug: &quot; + &quot;\n&quot; + &quot;Object: &quot; + ListOfUsers[i] + &quot;\n&quot; + &quot;Json: &quot; + JsonSerializer.Serialize&lt;User&gt;(ListOfUsers[i]));
          }
          for(int i=0; i&lt;ListOfShops.Count; i++){
              srShop.WriteLine(JsonSerializer.Serialize&lt;Shop&gt;(ListOfShops[i]), serializeOptions);
              Console.WriteLine(&quot;Debug: &quot; + &quot;\n&quot; + &quot;Object: &quot; + ListOfShops[i] + &quot;\n&quot; + &quot;Json: &quot; + JsonSerializer.Serialize&lt;Shop&gt;(ListOfShops[i]));
          }
  
          srUser.Close();
          fileUsers.Close();
          srShop.Close();
          fileShops.Close();
  
      }
  </code></pre>
  <p>How can I fix it? Thanks in advance! :)</p>
  <p>EDIT: I added the classes I'm trying to deserialize. I apologize if I'm not giving enough detail or I make dumb mistakes, I am still a student and trying to mess with most of these things for the first time</p>