Skip to content

Commit

Permalink
Rely on the Deprecated serialiser if type is know but regular deseria…
Browse files Browse the repository at this point in the history
…liser fails (inside of object changed)
  • Loading branch information
adecler committed Nov 6, 2019
1 parent 38fc8fe commit 0e265c9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Serialiser_Engine/Objects/BsonSerializers/ObjectSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,19 @@ private object DeserializeDiscriminatedValue(BsonDeserializationContext context,
}
catch
{
// If failed, just return the custom object
// If failed, try the deprecated object serialiser
context.Reader.ReturnToBookmark(bookmark);
Engine.Reflection.Compute.RecordWarning("Cannot find a definition of type " + actualType.FullName + " that matches the object to deserialise -> data returned as custom objects.");
IBsonSerializer customSerializer = BsonSerializer.LookupSerializer(typeof(CustomObject));
return customSerializer.Deserialize(context, args) as CustomObject;
IBsonSerializer customSerializer;
if (actualType != typeof(IDeprecated))
customSerializer = BsonSerializer.LookupSerializer(typeof(IDeprecated));
else
{
// Last resort: just return the custom object
Engine.Reflection.Compute.RecordWarning("Cannot find a definition of type " + actualType.FullName + " that matches the object to deserialise -> data returned as custom objects.");
customSerializer = BsonSerializer.LookupSerializer(typeof(CustomObject));
}

return customSerializer.Deserialize(context, args);
}
}

Expand Down

0 comments on commit 0e265c9

Please sign in to comment.