Hi,
I have simple proto definition like below and through the protoc compiler I
am able to use the generated C# message class to covert object to byte
array, de-serialize the object from byte array using the message parser etc.
When I try to use the JSON Formatter & parser, I am able to serialize the
same to JSON string, but during deserialization the JSON parser throws an
error about not able to convert System.UInt32 (.NET) to Google.
Will appreciate any help in resolving this. I am using
Google.Protobuf.3.1.0 and Google.Protobuf.Tools.3.1.0 nuget packages
Thanks.
*PROTO=====*
syntax = "proto3";
package testpack;
option csharp_namespace = "Test.v1";
// import proto definitions from google protobuf
import "wrappers.proto";
import "timestamp.proto";
message TestMessage {
google.protobuf.UInt32Value testUintProperty = 1;
google.protobuf.Int32Value testIntProperty = 2;
google.protobuf.BoolValue testBoolProperty = 3;
google.protobuf.Timestamp timestamp = 4;
}
*CODE SNIPPTES (C#)==================*
// this works
var testMessage = <some method to create TestMessage object using the
generated TestMessage class>
var tmBytes = testMessage.ToByteArray();
var deserializedTestMessage = TestMessage.Parser.ParseFrom(tmBytes);
// this works - json below
JsonFormatter jsf = new JsonFormatter(new
JsonFormatter.Settings(true));
string jsonString = jsf.Format(testMessage);
// this throws error - see exception details below
var deserializedTestMessageFromJson =
JsonParser.Default.Parse<TestMessage>(jsonString);
*JSON====*
{ "testUintproperty": 1024, "testIntproperty": 300, "testBoolproperty":
true, "timestamp": "2017-01-10T09:46:53.218325200Z" }
*SYSTEMEXCEPTION MESSAGE==========================*
Unable to cast object of type 'System.UInt32' to type
'Google.Protobuf.WellKnownTypes.UInt32Value'.
*STACK TRACE===========*
at lambda_method(Closure , IMessage , Object )
at Google.Protobuf.Reflection.SingleFieldAccessor.SetValue(IMessage
message, Object value)
at Google.Protobuf.JsonParser.MergeField(IMessage message,
FieldDescriptor field, JsonTokenizer tokenizer)
at Google.Protobuf.JsonParser.Merge(IMessage message, JsonTokenizer
tokenizer)
at Google.Protobuf.JsonParser.Merge(IMessage message, TextReader
jsonReader)
at Google.Protobuf.JsonParser.Parse[T](TextReader jsonReader)
at Google.Protobuf.JsonParser.Parse[T](String json)
at
DeviceSimulator.Program.<SendDeviceToCloudTestMessagesAsync>d__3.MoveNext()
...
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.