Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Key comparer is not preserved in serializing/deserializing immutable collections #75

Open
dbolin opened this issue Nov 11, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@dbolin
Copy link

dbolin commented Nov 11, 2019

Test code:

            var config = new SerializerConfig();
            config.UseImmutableFormatters();

            var s = new CerasSerializer(config);

            var o = ImmutableDictionary<string, int>.Empty.WithComparers(StringComparer.OrdinalIgnoreCase);

            var x = s.Serialize(o);

            var y = s.Deserialize<ImmutableDictionary<string, int>>(x);

            Console.WriteLine(o.KeyComparer.GetType());
            Console.WriteLine(y.KeyComparer.GetType());

Actual output:
System.OrdinalIgnoreCaseComparer
System.Collections.Generic.GenericEqualityComparer`1[System.String]

Expected output:
System.OrdinalIgnoreCaseComparer
System.OrdinalIgnoreCaseComparer

@dbolin dbolin added the bug Something isn't working label Nov 11, 2019
@rikimaru0345
Copy link
Owner

Yep, none of the collection formatters persist the equality comparer.

I guess that's something that should be fixed for some of them.

I think the commonly known types like list, hash set, dictionary,... Should have their equality comparer saved and restored.

For all others, it is not possible I think.
We can not assume anything about some custom IList implementation.

For those troublesome cases a custom formatter can be written (which is extremely).

For immutable collections I'll count that as a bug as well. I've added it to my Todo list.
Until then, you can use a custom formatter. (let me know if anything is unclear about that 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants