Override Default value for String variables

151 views
Skip to first unread message

Joel Dcunha

unread,
Jun 17, 2019, 2:41:53 PM6/17/19
to Protocol Buffers
Hi,

I have an issue when I am using protobuf for serialization and deserialization

Scenario 1:
    "profile" : {
      "subscriptions" : [
         {
            "id" : "xxx",
            "trigger" : {
               "aboveBelow" : "above",
               "threshold" : "200",
               "accounts" : [
                  {
                     "number" : "029010101029200",
                     "pc" : "DDA",
                     "spc" : "CA",
                     "currency" : "DOP"
                  }
               ]
            }
          }]
  }

Scenario 2:
         "profile" : {
      "subscriptions" : [
         {
            "id" : "xxx",
            "trigger" : {
               "aboveBelow" : "above",
               "threshold" : "200",
               "accounts" : [
                  {
                     "number" : "XXXXX",
                     "pc" : "XXX",
                     "spc" : "XXX",
                     "currency" : "XX",
                     "cardNumber":""
                  }
               ]
            }
          }]
  }
    
Now both scenarios are valid but since the default for string in Protobuf is empty I cannot write a generic code for the variable cardNumber as in if I use the empty string check than my scenario 2 fails and if if I ignore the empty check my scenario 1 fails.
I am expecting the same json   before and after serailization/deserialization . So is there a way I can have the string variables to have a default value when deserializing.

Thanks,
Joel

Hao Nguyen

unread,
Jun 25, 2019, 10:38:34 AM6/25/19
to Protocol Buffers
Reply all
Reply to author
Forward
0 new messages