Add extension data support to Json serializer#37690
Add extension data support to Json serializer#37690steveharter merged 3 commits intodotnet:masterfrom
Conversation
| Debug.Assert(entry.Key is string); | ||
|
|
||
| string propertyName = (string)entry.Key; | ||
| element.WriteAsProperty(propertyName, writer); |
There was a problem hiding this comment.
Similarly, I think we may need the explicit call to AsSpan() (since the span to string implicit converter is on core only)
We should just add the WriteAsProperty string-based overload to JsonElement to avoid this concern all together.
System\Text\Json\Serialization\JsonSerializer.Write.HandleDictionary.cs(164,41): error CS1503: Argument 1: cannot convert from 'string' to 'System.ReadOnlySpan'
There was a problem hiding this comment.
Did you start a separate discussion to add the public API?
For now, I'll just do the AsSpan(). When the overload is added we will need to check for all usages and clean up as appropriate.
There was a problem hiding this comment.
Did you start a separate discussion to add the public API?
Yes. Added the overload. See: #37789
| <value>The data extension property '{0}.{1}' does not match the required signature of IDictionary<string, JsonElement> or IDictionary<string, object>.</value> | ||
| </data> | ||
| <data name="SerializationDuplicateAttribute" xml:space="preserve"> | ||
| <value>The attribute '{0}' cannot exist on more than one property.</value> |
There was a problem hiding this comment.
Should we add, within the same class?
There was a problem hiding this comment.
Is this better: A class cannot have more than one property that has the attribute '{0}'.
There was a problem hiding this comment.
Is this better
Yes.
However, re-thinking about this, what happens when we add struct support? Is there a generic term that can encapsulate both .NET structs and classes? Type? Object?
Maybe type definition?
A type definition cannot have more than one property that has the attribute '{0}'.
|
There is some feedback that will be addressed in a future commit. |
Replaces PR #37578 which had issues with a corrupt branch.
Adds the overflow or data extension support via the new JsonExtensionDataAttribute
Other changes:
Open issues:
ExtensionDataPropertyNamingproperty. The existing naming policies for normal properties and dictionary keys.