Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.9k stars 433 forks source link

Serialization exception caused by multiple nullable parameters #856

Closed SmRiley closed 1 month ago

SmRiley commented 1 month ago

In the initial design, require was intended to be used only for optional parameters in Swagger. However, with the emergence of this issue and the integration of the corresponding nullable options, it became possible to have multiple nullable parameters. When multiple nullable parameters are all null, the serialization of the body does not handle this scenario, leading to the following exception:

Newtonsoft.Json.JsonSerializationException: No JSON content found and type 'MagicOnion.DynamicArgumentTuple`2[System.Nullable`1[System.Int32],System.Nullable`1[System.Int32]]' is not nullable. Path '', line 0, position 0.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type)
   at MagicOnion.Server.HttpGateway.MagicOnionHttpGatewayMiddleware.Invoke(HttpContext httpContext) in .\MagicOnion.Server.HttpGateway\MagicOnionHttpGatewayMiddleware.cs:line 138

My solution is to add similar code, but I don't know if there is a better way to detect that it is a class under DynamicArgumentTuple. httpGateway will be deleted in release 7, and no one has raised this point for so long. I wonder if no one has noticed this. image

SmRiley commented 1 month ago

If it needs to be addressed, I will submit a PR.