So, I have a custom class 'User' like this:
class User
{
string firstname;
string lastname;
string proposedname;
public User(string firstname, string lastname)
{
this.firstname = firstname;
this.lastname = lastname;
this.proposedname = $"{firstname}.{lastname}".ToLower();
}
}
And another Class "UserCreator that has a method "GenerateList" and a method "WriteList" as well as a field which is simply a List :
public class UserCreator
{
internal List<User> Users;
public UserCreator(int n = 1000)
{
Users = new List<User>();
this.GenerateList(n);
}
public void WriteList(string outputPath)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this.Users, Newtonsoft.Json.Formatting.Indented);
System.IO.File.WriteAllText(outputPath, json);
}
void GenerateList(int amount)
{
List<User> result = new List<User>();
///...
this.Users = result;
}
}
Everything works just fine until it get's to the Serialization part in WriteList(). Instead of working as Intended I get something like this:
[
{},
{},
{},
{},
{},
{},
{},
{}
]
I'm guessing it has to do with the fact that I'm using a List of a custom Class. Is that a known limitation of Newtonsoft.Json? Or maybe due to Access modifiers?