Closed inethui closed 2 years ago
Deserializer calls ToSurrogate
first to convert the old value into surrogate, then does deserialization onto it and calls FromSurrogate
.
It looks like the issue happens because the code doesn't expect surrogate to change null to non-null and vice versa.
This code works without the exception:
[AqlaSerializer.SurrogateConverter]
public static CoreTable FromSurrogate(CoreTableSurrogate surrogate)
{
if (surrogate == null)
return null;
return new CoreTable();
}
[AqlaSerializer.SurrogateConverter]
public static CoreTableSurrogate ToSurrogate(CoreTable coreTable)
{
if (coreTable == null)
return null;
var surrogate = new CoreTableSurrogate();
surrogate.ObjectId = nextObjectId++;
return surrogate;
}
Thanks for the quick response. I still have a question, why is "ToSurrogate" called twice, one with not-null "coreTable" parameter, and the other with null "coreTable" parameter?
Another (first) time it's called during serialization.
Thanks for the explanation. What is the purpose of 2? It's really confusing.
You can deserialize onto an existing instance. So the existing value first must be converted into a surrogate and then deserialization is applied onto it.
Is this something internally needed by Aqla? I just can't think of a use case while I would deserialize onto an existing instance.
It's a publicly available API, you can pass an existing object into Deserialize method.
I see. Thanks a lot for the replies. I really appreciate it.
No issue, questions are answered.
The following test throws "AqlaSerializer.ProtoException : A deferred key does not have a value yet (NoteObject call missed?)". Also, the method "CoreTableSurrogate.ToSurrogate" is called twice, the first call with non-null "coreTable" parameter, the second call with null "coreTable" parameter. It seems that the result of the second call is passed to "CoreTableSurrogate.FromSurrogate".
Any idea why it behaves like this? Thanks