-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix preserved reference surrogate in collection deserialization bug #264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,16 @@ internal sealed class FromSurrogateSerializer : ValueSerializer | |
{ | ||
private readonly ValueSerializer _surrogateSerializer; | ||
private readonly Func<object, object> _translator; | ||
private readonly bool _preserveObjectReferences; | ||
|
||
public FromSurrogateSerializer(Func<object, object> translator, ValueSerializer surrogateSerializer) | ||
public FromSurrogateSerializer( | ||
Func<object, object> translator, | ||
ValueSerializer surrogateSerializer, | ||
bool preserveObjectReferences) | ||
{ | ||
_translator = translator; | ||
_surrogateSerializer = surrogateSerializer; | ||
_preserveObjectReferences = preserveObjectReferences; | ||
} | ||
|
||
public override void WriteManifest(Stream stream, SerializerSession session) | ||
|
@@ -37,6 +42,8 @@ public override object ReadValue(Stream stream, DeserializerSession session) | |
{ | ||
var surrogateValue = _surrogateSerializer.ReadValue(stream, session); | ||
var value = _translator(surrogateValue); | ||
if(_preserveObjectReferences) | ||
session.ReplaceOrAddTrackedDeserializedObject(surrogateValue, value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace the wrongly injected surrogate object with the actual deserialized de-surrogated value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boy this must have been a fun one to track down. |
||
return value; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method will search the current reference array for surrogated object instance and replace it with the actual object reference value