Skip to content

Commit

Permalink
bugfix not using know serializers when defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Sep 23, 2020
1 parent e5d4900 commit 6bafc4c
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/Hyperion/SerializerFactories/ArraySerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
WriteValues((dynamic)arr, stream, elementType, elementSerializer, session);
};
arraySerializer.Initialize(reader, writer);
typeMapping.TryAdd(type, arraySerializer);

if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(arraySerializer, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, arraySerializer);
return arraySerializer;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var os = new ObjectSerializer(type);
typeMapping.TryAdd(type, os);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(os, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, os);
ObjectReader reader = (stream, session) =>
{
var owner = stream.ReadObject(session) as Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var ser = new ObjectSerializer(type);
typeMapping.TryAdd(type, ser);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(ser, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, ser);
var elementSerializer = serializer.GetSerializerByType(typeof (DictionaryEntry));
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
ObjectReader reader = (stream, session) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var os = new ObjectSerializer(type);
typeMapping.TryAdd(type, os);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(os, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, os);
var methodInfoSerializer = serializer.GetSerializerByType(typeof(MethodInfo));
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
ObjectReader reader = (stream, session) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
{
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
var ser = new ObjectSerializer(type);
typeMapping.TryAdd(type, ser);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(ser, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, ser);
var dictionaryTypes = GetKeyValuePairType(type);
var elementSerializer = serializer.GetSerializerByType(dictionaryTypes.KeyValuePairType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var x = new ObjectSerializer(type);
typeMapping.TryAdd(type, x);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(x, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, x);

var preserveObjectReferences = serializer.Options.PreserveObjectReferences;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
StringSerializer.WriteValueImpl(stream, stackTraceString, session);
stream.WriteObjectWithManifest(innerException, session);
});
typeMapping.TryAdd(type, exceptionSerializer);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(exceptionSerializer, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, exceptionSerializer);
return exceptionSerializer;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
{
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;
var ser = new ObjectSerializer(type);
typeMapping.TryAdd(type, ser);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(ser, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, ser);
var elementSerializer = serializer.GetSerializerByType(typeof(DictionaryEntry));

ObjectReader reader = (stream, session) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var x = new ObjectSerializer(type);
typeMapping.TryAdd(type, x);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(x, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, x);

var elementType = GetEnumerableType(type);
var arrType = elementType.MakeArrayType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var x = new ObjectSerializer(type);
typeMapping.TryAdd(type, x);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(x, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, x);

var keyType = GetKeyType(type);
var valueType = GetValyeType(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var os = new ObjectSerializer(type);
typeMapping.TryAdd(type, os);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(os, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, os);
ObjectReader reader = (stream, session) =>
{
var name = stream.ReadString(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var x = new ObjectSerializer(type);
typeMapping.TryAdd(type, x);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(x, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, x);
var preserveObjectReferences = serializer.Options.PreserveObjectReferences;

var elementType = GetEnumerableType(type) ?? typeof (object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var os = new ObjectSerializer(type);
typeMapping.TryAdd(type, os);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(os, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, os);
ObjectReader reader = (stream, session) =>
{
var name = stream.ReadString(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
WriteValues((Array)arr, stream, elementType, elementSerializer, session);
};
arraySerializer.Initialize(reader, writer);
typeMapping.TryAdd(type, arraySerializer);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(arraySerializer, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, arraySerializer);
return arraySerializer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public override ValueSerializer BuildSerializer(Serializer serializer, Type type
ConcurrentDictionary<Type, ValueSerializer> typeMapping)
{
var os = new ObjectSerializer(type);
typeMapping.TryAdd(type, os);
if (serializer.Options.KnownTypesDict.TryGetValue(type, out var index))
{
var wrapper = new KnownTypeObjectSerializer(os, index);
typeMapping.TryAdd(type, wrapper);
}
else
typeMapping.TryAdd(type, os);
ObjectReader reader = (stream, session) =>
{
var name = stream.ReadString(session);
Expand Down

0 comments on commit 6bafc4c

Please sign in to comment.