Check realoneof in json parsing (#7763)
* Check realoneof in json parsing
* Fix whichoneof to also work for synthetic oneof
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index ea8bd65..cea1e6a 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -344,6 +344,24 @@
$this->assertSame(0, $m2->getTrueOptionalInt32());
}
+ public function testJsonEncodeDecodeOptional()
+ {
+ $m = new TestMessage();
+ $this->assertFalse($m->hasTrueOptionalInt32());
+ $data = $m->serializeToJsonString();
+ $this->assertSame("{}", $data);
+
+ $m->setTrueOptionalInt32(0);
+ $this->assertTrue($m->hasTrueOptionalInt32());
+ $data = $m->serializeToJsonString();
+ $this->assertNotSame("{}", $data);
+
+ $m2 = new TestMessage();
+ $m2->mergeFromJsonString($data);
+ $this->assertTrue($m2->hasTrueOptionalInt32());
+ $this->assertSame(0, $m2->getTrueOptionalInt32());
+ }
+
public function testJsonEncodeDecodeOneof()
{
$m = new TestMessage();