Fix Primitive Collection serialization #6157
Open
+29
−13
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.
This was broken by both #5871 and #5682:
List<Guid>
was serialized, it was recognized as a primitive collection and thus plainly written to the JSON without any type information:["d4d8404c-4357-47ff-a343-649a116539f5"]
List<object>
, containingstring
s. This is already not good.List<object>
gets serialized again (e.g. due to multiple workflow suspends causingWorkflowState
serialization), this time it fails the primitive collection recognition, becauseobject
is not a primitive type. It now gets serialized as{"_items": ["d4d8404c-4357-47ff-a343-649a116539f5"], "_type": "Object[]"}
ReadType(...)
butReadType
fails to parseObject[]
since it lacks the logic fromTypeJsonConverter
to throw away the[]
before looking upObject
in theWellKnownTypeRegistry
, so it returnsnull
as a type. Without a type but being faced with a json object{ ... }
it now deserializes into anExpandoObject
What is the motivation behind the
WellKnownTypeRegistry
? It seems to hugely complicate the codebase for little benefit and is handled inconsistently, it is being used in many places without the special logic around recognizing collections, which sometimes works on ICollection, sometimes on Lists, attaching[]
or not, using the word "array" when aList
is meant, etc.Also is there a reason for reinventing the polymorphic serialization wheel, when STJ supports it out of the box?
Additionally i've adjusted theWrite
method to write the_type
field first so that theRead
method does not have to skip over all the content while searching for_type
.This change is