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

TypeManifest written, even if Type is registered via "knownTypes" #183

Open
jogibear9988 opened this issue Sep 23, 2020 · 3 comments
Open

Comments

@jogibear9988
Copy link
Contributor

jogibear9988 commented Sep 23, 2020

Try this Code:

    class Temp
    {
        public object[] SubArray { get; set; }
    }

    [Fact]
    public void WritesManifestEvenIfKnown()
    {
        var stream = new MemoryStream();
        var msg = new Temp() { SubArray = new object[] { 1, 2, 3 } };
        var serializer = new Serializer(new SerializerOptions(knownTypes: new[] { typeof(Temp), typeof(object[]) }));
        serializer.Serialize(msg, stream);
        stream.Position = 0;
        var res = serializer.Deserialize(stream);
    }

Manifest for "object[]" ist still written, even if it's known

@jogibear9988
Copy link
Contributor Author

jogibear9988 commented Sep 23, 2020

Changeing following line in ArraySerializerFactory
from

  typeMapping.TryAdd(type, arraySerializer);

to:

        if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
        {
            var wrapper = new KnownTypeObjectSerializer(arraySerializer, index);
            typeMapping.TryAdd(type, wrapper);
        }
        else
            typeMapping.TryAdd(type, arraySerializer);

would fix it, but don't know if it's okay

@jogibear9988
Copy link
Contributor Author

In Dictionay Serilizer the same,

change

            typeMapping.TryAdd(type, ser);

to

        if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
        {
            var wrapper = new KnownTypeObjectSerializer(ser, index);
            typeMapping.TryAdd(type, wrapper);
        }
        else
            typeMapping.TryAdd(type, ser);

@jogibear9988
Copy link
Contributor Author

@Arkatufus
do you have a plan for a new nuget release?

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

No branches or pull requests

1 participant