Describe the bug
I'm trying to deserialize this json
{
"name": "updated_name",
"description": "updated_description",
"restriction": "Closed",
"matchType": null,
"maxPlayers": 8,
"newHost": null
}
to below proto message
message UpdateLobby {
google.protobuf.StringValue name=1;
google.protobuf.StringValue description=2;
google.protobuf.StringValue restriction=3;
google.protobuf.StringValue matchType=4;
google.protobuf.Int32Value maxPlayers=5;
google.protobuf.StringValue newHost=6;
}
but it fails with exception
System.Text.Json.JsonException: The JSON value could not be converted to Google.Protobuf.WellKnownTypes.StringValue.
at Protobuf.System.Text.Json.ProtobufConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at Protobuf.System.Text.Json.InternalConverters.FieldConverter`1.Read(Utf8JsonReader& reader, IMessage obj, Type typeToConvert, JsonSerializerOptions options, IFieldAccessor fieldAccessor)
at Protobuf.System.Text.Json.ProtobufConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at BeamableGateway.Formatters.ProtoBufJsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding) in xxx\ProtoBufJsonInputFormatter.cs:line 41
Expected behavior
Maybe I'm missing something but looks like above json should be deserializable to UpdateLobby.
Environment:
- OS: Windows 11
- Version: 1.0.4
Additional context
Here is sample reproduceable example
var jsonSerializerOptions = new JsonSerializerOptions();
jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
jsonSerializerOptions.AddProtobufSupport();
var updateLobby = JsonSerializer.Deserialize<UpdateLobby>(
"{\"name\":\"updated_name\",\"description\":\"updated_description\",\"restriction\":\"Closed\",\"matchType\":null,\"maxPlayers\":8,\"newHost\":null}",
jsonSerializerOptions);
Thanks for your time and effort you put into this project 👍
Describe the bug
I'm trying to deserialize this json
to below proto message
but it fails with exception
Expected behavior
Maybe I'm missing something but looks like above json should be deserializable to
UpdateLobby.Environment:
Additional context
Here is sample reproduceable example
Thanks for your time and effort you put into this project 👍