TypeManifest written, even if Type is registered via "knownTypes"
jogibear9988 opened this issue · 3 comments
jogibear9988 commented
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 commented
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 commented
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 commented
@Arkatufus
do you have a plan for a new nuget release?