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

Add a test where the manifest for collections of a known type aren't … #346

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

AppcenterAucxis
Copy link

Hi I'm using Hyperion as the serializer and I know all my types beforehand so I'm trying to use the knownType array. It seems that generic List aren't counted as knownTypes.

Example:

public class Program
{
    static void Main(string[] args)
    {
        var stream = new MemoryStream();
        var msg = new Parent()
        {
            Name = "Sander",
            Children = new List<Child>()
            {
                new Child() { Name = "Juuls", },
                new Child() { Name = "Raeven", },
            },
        };
        var knownTypes = new[]
        {
            typeof(string),
            typeof(Parent),
            typeof(Child),
            msg.Children.GetType(), //same as typeof(List<Child>)
        };

        var serializer = new Serializer(new SerializerOptions(false, false, null, null, knownTypes, false, null, false, null));
        serializer.Serialize(msg, stream);
        stream.Position = 0;
        var a = stream.ToArray();
        var text = string.Join("", a.Select(x => x < 32 || x > 126 ? "" : ((char)x).ToString()));
        var res = (Parent)serializer.Deserialize(stream);
        Console.WriteLine(text); // output = "bSystem.Collections.Generic.List1[[ConsoleApp1.Child, ConsoleApp1]], System.Private.CoreLib,%core%JuulsRaevenSander"
        Console.ReadLine();
    }
}

public class Parent
{
    public string Name { get; set; }
    public List<Child> Children { get; set; }
}

public class Child
{
    public string Name { get; set; }
}

Result:
bSystem.Collections.Generic.List1[[ConsoleApp1.Child, ConsoleApp1]], System.Private.CoreLib,%core%JuulsRaevenSander

Expected result:
No mention of "System.Collections.Generic.List"

Aaronontheweb:
"yeah sounds like the knownTypes mechanism is pretty perscriptive and doesn't have innate support for counting collections of knownTypes too. Do you think you could submit a PR for that?

I'll meet you half way - submit a failing PR to the repo that reproduces the problem and someone from our team will look into it"

Fixes #

Changes

I have added a test with a list of poco's, which now fails because the serializer still contains "System.Collections.Generic.List"

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Latest dev Benchmarks

Include data from the relevant benchmark prior to this change here.

This PR's Benchmarks

Include data from after this change here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants