-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception occurs when using System.Text.Json deserializer to deserialize enum. #1832
Comments
I've fixed the enum bug, but the unit-test has identified a second bug. The generator generates the following code: if (instance.AdditionalProperties == null)
{
instance.AdditionalProperties = new Dictionary<string, dynamic>();
}
var deserializedValue = JsonSerializer.Deserialize<Dictionary<string, dynamic>?>(ref reader, options);
instance.AdditionalProperties.Add(propertyName, deserializedValue);
continue; Which fails on the call to
However, the generated code looks very wrong - I don't think it should be deserializing to a dictionary, but to a simple |
A third bug is that Therefore, when attempting to serialize a deserialized model, one gets the following error:
For example, "members": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
}
]
}, will cause the error on this serailization code: if (value.Members != null)
{
// write property name and let the serializer serialize the value itself
writer.WritePropertyName("members");
JsonSerializer.Serialize(writer, value.Members, options);
} |
I've fixed the bugs I've mentioned above, but I have a concern that deserializing to Perhaps this can be looked into in a future issue? However, without adding type-annotations to the output JSON, it's likely that there is no sensible way around this, so 🤷 . |
/rtm |
The existing
runtime-csharp
unit-tests do not currently test deserialization. When adding such a test, a bug is exposed.Steps to reproduce
Add the following unit-test in the
runtime-csharp
test solution under\test\models\json_serializer
.Run the test.
Expected outcome
The JSON is correctly deserialized to the relevant model and the test passes.
Actual outcome
An exception occurs:
Technical detail
This is caused by the following generated code in the generated
JsonConverter<T>
:Note the call to
Deserialize<dynamic>
- this should beDeserialize<string>
.The text was updated successfully, but these errors were encountered: