In many of our supported languages, you can find an option in the 
JsonFormat printer to include the default value. e.g.,
https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/util/JsonFormat.Printer#includingDefaultValueFields--
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.util.json_util#JsonPrintOptions.always_print_primitive_fields.details
https://developers.google.com/protocol-buffers/docs/reference/python/google.protobuf.json_format-pysrc#MessageToJson

Hao

On Monday, June 17, 2019 at 11:41:53 AM UTC-7, Joel Dcunha wrote:
>
> 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
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/1ab61465-18cd-4f0d-bdbc-54b61dfcf3aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to