Repository navigation
[DRAFT]JsonExtensionData should allow non-JsonElement types during serialization - #38262
MarcoRossignoli wants to merge 2 commits into
Conversation
|
@MarcoRossignoli I wouldn't change the semantics of how deserialization occurs. The only thing that's necessary to have a good experience with the attribute is to remove this check: https://github.com/dotnet/corefx/blob/master/src/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.HandleDictionary.cs#L141 |
|
@pranavkm I don't think that remove that check is enough...only entry value of type If you confirm that it's ok keep deserialization asis(all |
That seems perfectly reasonable. |
As @pranavkm mentioned, this should only be fixed for the serialization side. The deserialization should continue to be as JsonElement (and not other strongly typed types). |
| Assert.IsType<double>(obj.MyOverflow["key"]); | ||
| Assert.Equal(1e-005, (double)obj.MyOverflow["key"]); | ||
|
|
||
| obj = JsonSerializer.Parse<ClassWithExtensionPropertyAsObject>(@"{""MyOverflow"":{""key"":1.1}}"); |
There was a problem hiding this comment.
We do not want to "guess" here. We just want to create JsonElement on deserialize.
There was a problem hiding this comment.
Ok understood thanks
|
Thank's to all for fast feedback, close this for now because I get all answers I needed, tomorrow(CET) I'll PR final code. |
| @@ -40,34 +40,27 @@ private static bool HandleDictionary( | |||
| // Handle DataExtension. | |||
| if (ReferenceEquals(jsonPropertyInfo, state.Current.JsonClassInfo.DataExtensionProperty)) | |||
There was a problem hiding this comment.
I think we just need to remove lines 41-45 (and the WriteExtensionData method) + update tests.
working on https://github.com/dotnet/corefx/issues/38238
THIS IS A TMP DRAFT PR(INCOMPLETE) TO DISCUSS THE ISSUE, I'LL CLOSE.
Fix serialization it's not a great problem, the hard part is understand how to handle "deserialization" of numbers/object.
I tested Newtonsoft.Json and I would know if should be ok behave in the same way.
Result
@steveharter @ahsonkhan before go on and prepare a complete PR I would like to know if I'm on right way or if there was another plan, thank's!
Or should we allow serialization and left deserialization to add only JsonElement on deserialization?
cc: @pranavkm