Protobuf: PHP Google\Protobuf\Internal\Message\serializeToJsonString error

Created on 15 Mar 2018  ·  6Comments  ·  Source: protocolbuffers/protobuf

Test.proto

syntax="proto3";

message Test {
    map <int32, string> v   = 1;
}

Test.php

<?php

require_once __DIR__ . '/pb/GPBMetadata/Test.php';
require_once __DIR__ . '/pb/Test.php';

$obj    = new \Test();
$obj->setV(array('0' => 't0', '2' => 't2'));

echo $obj->serializeToJsonString();

Expected result:

{"v":{"0":"t0","2":"t2"}}

Actual result:

{"v":{"t0","2":"t2"}}
P2 bug php

All 6 comments

Are you using c extension?

Could reproduce the issue with version 3.5.1, full testcase available at https://github.com/jbq/protobuf-bug-4389:

With C extension
{"v":{"t0","2":"t2"}}

Without C extension
{"v":{"0":"t0","2":"t2"}}

@TeBoring Yes.

This is a known issue. We have a plan to fix json conformance test for c extension. This will be fixed together.

这个问题怎么解决的?不光是0,false也会被过滤

这个问题怎么解决的?不光是0,false也会被过滤

解决了吗?

Was this page helpful?
0 / 5 - 0 ratings