Updating constructor matching for int keys#1277
Merged
AArnott merged 3 commits intoMessagePack-CSharp:masterfrom Jul 14, 2021
seriousbox:fix-int-key-constructor-matching
Merged
Updating constructor matching for int keys#1277AArnott merged 3 commits intoMessagePack-CSharp:masterfrom seriousbox:fix-int-key-constructor-matching
AArnott merged 3 commits intoMessagePack-CSharp:masterfrom
seriousbox:fix-int-key-constructor-matching
Conversation
AArnott
requested changes
Jul 1, 2021
Collaborator
AArnott
left a comment
There was a problem hiding this comment.
It's a peculiar use case, but I guess I can imagine how folks may land there. Thinking about it, I can't see how this change would present any problem.
But we do want a test for it. Can you add one?
@neuecc how do you feel about it?
Contributor
Author
Yes, I will add it today. |
Member
|
Sorry, I missed that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The following example works fine for mutable objects.
Unfortunately, it is impossible to repeat the same thing for immutable objects. Serializing the following example throws an exception: MessagePack.MessagePackSerializationException {"Failed to serialize Example value."}. InnerException: MessagePack.Internal.MessagePackDynamicObjectResolverException {"can't find matched constructor. type:Example "}.
The current implementation searches for the matched constructor according to the following logic: for each constructor parameter, there must be int key with value of the index of this parameter. So for immutable types, keys must start with 0 and have no gaps. It becomes more difficult to support changes for such types.
I propose a new implementation without breaking backward compatibility. We determine the indexes of the constructor parameters corresponding to the int keys in ascending order of their values.
This implementation does not break the current serialization logic and supports missing keys in the previous example.