I have a proto file which contains the below in it
message OuterMessage{oneof instanceOrGroup { string PropertyA = 10; string PropertyB = 60; } }I generated C# class using protoc and on an instance of that class I set its first property as below.
Then I serialized/de-serialized the class using NewtonSoft.Json as below
ProtoGenCSharpClass obj = ....
obj.PropertyA = "abc"
string jsonConvertStr = NewtonSoft.Json.JsonConvert.SerializeObject(obj);
ProtoGenCSharpClass deserialzedObj = NewtonSoft.Json.JsonConvert.DeserializeObject<ProtoGenCSharpClass>(jsonConvertStr);
at this point i see that the value set on the "PropertyA" property got wiped out.
What am I missing here? Do i need to write a custom converter or something? Or is there an issue in the proto file?
Original issue i was having was when I convert this object into a json string and then sent that as a StringContent to rest api
//Calling code
var content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json");
HttpResponseMessage response = await Task.Run(async () => await serviceClient.PostAsync(queryString, content));
//Web api
[HttpPost]
[Route("saveOrder")]
[Route("saveOrder/{Id}")]
public async Task SaveOrder([FromUri] string Id, [FromBody] ProtoGenCSharpClass myObj)
{....
// at this point the myObj.PropertyA is emtpy
}
===================================
Please see the attached sample application files... I have used "Google.protobuf" and "Newtonsoft.Json" as nuget packages.
122806-simplified-cs.txt122746-program-cs.txt122739-simplified-proto.txt
Please advice.
Thanks
Jay
