I have RepeatedMessage in my proto file,  I am able to create C# object of 
my proto and serialize it and so..whereas , when I pass the value via JSON 
with only one value in collection , it threw error as 

Unhandled Exception: Google.Protobuf.InvalidProtocolBufferException: 
Repeated field value was not an array. Token type: StartObject
   at Google.Protobuf.JsonParser.MergeRepeatedField(IMessage message, 
FieldDescriptor field, JsonTokenizer tokenizer)
   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(TextReader jsonReader, 
MessageDescriptor descriptor)
   at Google.Protobuf.JsonParser.Parse(String json, MessageDescriptor 
descriptor)


My question is , how to have only one value in RepeatedMessageField, how to 
set this in JSON parser settings ?

Repeated Message is : desiredParameters


I am using Google protobuf JSON parser to parse JSON value,

  Google.Protobuf.JsonParser parser = Google.Protobuf.JsonParser.Default;
            IMessage tt = parser.Parse(json, descriptor);


And Error JSON value is 

{
  "destinationPort": "25",
  "desiredParameters": [
    {
      "context": "J1939_PGN",
      "value": "12340000"
    }
  ]
}

 
Where as if I give two or more desired parameters list as like below , then 
it works, 

{
  "destinationPort": "25",
  "desiredParameters": [
    {
      "context": "J1939_PGN",
      "value": "12340000"
    },
    {
      "context": "J1939_SPN",
      "value": "1245"
    }
  ]
}


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/17c7212e-58fd-4010-9604-6fa54e6dc011%40googlegroups.com.

Reply via email to