I am currently attempting to build an ASP.NET Core API.
On startup it checks if there is anything in its EF Core powered DB. If not it reads a few JSON files and fills it up. To do that it needs to Deserialize them. One of the properties is a List of strings and EF Core doesn't like that. To get around it I made a dummy Model.
public class StringModel
{
public int id { get; set; }
public string str { get; set; }
}
And the other Model.
public class Book
{
public int id { get; set; }
public virtual List<StringModel> chapters { get; set; }
}
This is not how my models look. This is a minimum reproducible example.
JSON
[{
chapters: ["a","b"]
}, {
chapters: ["foo","bar"]
}]
And this is where it throws
string json = GetJSONFromFile();
var objs = JsonConvert.DeserializeObject<List<Book>>(json);
Newtonsoft.Json.JsonSerializationException: 'Error converting value "a" to type 'Project.Models.Primitives.StringModel'. Path '[0].chapters[0]'
Any ideas?