Skip to content

IDictionary<,> being serialized wrong #56

@caunt

Description

@caunt

IDictionary<,> and IReadOnlyDictionary<,> is being serialized as array type and cannot be deserialized back to Test type
(normal Dictionary works btw)

Code to Reproduce:

using System;
using System.Collections.Generic;
using Tomlet;
					
var test = new Test();
var toml = TomletMain.TomlStringFrom(test);
Console.WriteLine(toml);

class Test
{
    IDictionary<string, string> Value { get; set; } = new Dictionary<string, string>() 
    {
        ["hello"] = "world"
    };
}

Output:

[[Value]]
key = "hello"
value = "world"
Key = "hello"
Value = "world"

Deserializing back:

test = TomletMain.To<Test>(toml);

Output:

Unhandled exception. System.ArgumentException: Object of type 'System.String[]' cannot be converted to type 'System.Collections.Generic.IDictionary`2[System.String,System.String]'.
   at System.RuntimeType.CheckValue(Object& value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at Tomlet.TomlCompositeDeserializer.<>c__DisplayClass0_2.<For>b__7(TomlValue value) in /_/Tomlet/TomlCompositeDeserializer.cs:line 116
   at Tomlet.TomletMain.To(Type what, TomlValue value, TomlSerializerOptions options) in /_/Tomlet/TomletMain.cs:line 65
   at Tomlet.TomletMain.To(Type what, String tomlString, TomlSerializerOptions options) in /_/Tomlet/TomletMain.cs:line 41
   at Tomlet.TomletMain.To[T](String tomlString, TomlSerializerOptions options) in /_/Tomlet/TomletMain.cs:line 26

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions