This repository was archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
This repository was archived by the owner on Oct 19, 2020. It is now read-only.
Incorrect behaviour when serializing array of tables within table. #14
Copy link
Copy link
Closed
Description
I created this repro case:
public class SubTable
{
public class ListTable
{
public int SomeValue { get; set; } = 5;
public override string ToString()
{
return $"ListTable({SomeValue})";
}
}
public List<ListTable> Values { get; set; } = new List<ListTable>();
public override string ToString()
{
return $"SubTable({string.Join(",", Values.Select(p => p.ToString()))})";
}
}
public class RootTable
{
public SubTable SubTable { get; set; } = new SubTable();
public override string ToString()
{
return $"RootTable({SubTable})";
}
}
class Program
{
static void Main(string[] args)
{
var root = new RootTable();
root.SubTable.Values.AddRange(new[]
{new SubTable.ListTable() {SomeValue = 1}, new SubTable.ListTable() {SomeValue = 5}});
Console.WriteLine("Before: {0}", root);
Console.WriteLine("=== Output TOML: ===");
var toml = Nett.Toml.WriteString(root);
Console.WriteLine(toml);
Console.WriteLine("=== END TOML ===");
var readRoot = Nett.Toml.ReadString(toml).Get<RootTable>();
Console.WriteLine("After: {0}", readRoot);
Console.ReadKey(true);
}
}When running I get this output:
Before: RootTable(SubTable(ListTable(1),ListTable(5)))
=== Output TOML: ===
[SubTable]
[[Values]]
SomeValue = 1
[[Values]]
SomeValue = 5
=== END TOML ===
After: RootTable(SubTable())
The deserialized object does not match the original object.
I'm new to TOML so I may be wrong, but I'd expect the output TOML to be this:
[SubTable]
[[SubTable.Values]]
SomeValue = 1
[[SubTable.Values]]
SomeValue = 5
And indeed, reading this TOML returns the correct values:
var testRead =
Nett.Toml.ReadString(
"[SubTable]\r\n\r\n[[SubTable.Values]]\r\nSomeValue = 1\r\n[[SubTable.Values]]\r\nSomeValue = 5")
.Get<RootTable>();Returns RootTable(SubTable(ListTable(1),ListTable(5)))
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels