PHP protobuf not returning value if default 0

14 views
Skip to first unread message

Gaz Nicoll

unread,
Sep 28, 2020, 12:50:26 PM9/28/20
to Protocol Buffers

What version of protobuf and what language are you using?
Version: v3.13.0 / v4.0.0RC2
Language: PHP 7.2.20
OS: macOS Catalina 10.15.6 / Amazon Linux AMI release 2018.03

We have implemented the Google Maps Booking API proto which is proto3. The Reserve with Google team are requesting that we explicitly return some values but where we need the value to be 0. protobuf-php is returning an empty array when we call serializeToJsonString() for example

namespace Ext\Maps\Booking\Feeds;

$cancellationPolicy = new CancellationPolicy;
$refundCondition = new CancellationPolicy\RefundCondition;

$refundCondition->setMinDurationBeforeStartTimeSec(0);
$refundCondition->setRefundPercent(0);

$cancellationPolicy->setRefundCondition([$refundCondition]);
echo $cancellationPolicy->serializeToJsonString();

will return

{"refundCondition":[{}]}

while Reserve with Google are requesting it return

{"refundCondition":[{"minDurationBeforeStartTimeSec":"0","refundPercent":0}]}

Looking at Google\Protobuf\Internal\Message I think returning an empty array would be the expected behaviour or is there something we can do change that?

Thanks

Gaz
Reply all
Reply to author
Forward
0 new messages