diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index 28ba83b011..b0405618a7 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -23,7 +23,6 @@ Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput Required.TimestampProtoInputTooLarge.JsonOutput Required.TimestampProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.BoolMapField.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 8008d88989..21c6a7bce5 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -1163,7 +1163,7 @@ static void put_optional_value(const void* memory, int len, #define T(upbtypeconst, upbtype, ctype, default_value) \ case upbtypeconst: { \ ctype value = DEREF(memory, 0, ctype); \ - if (value != default_value) { \ + if (is_json || value != default_value) { \ upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); \ upb_sink_put##upbtype(sink, sel, value); \ } \ @@ -1181,8 +1181,7 @@ static void put_optional_value(const void* memory, int len, #undef T case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - putrawstr(memory, len, f, sink, - is_json && is_wrapper_msg(upb_fielddef_containingtype(f))); + putrawstr(memory, len, f, sink, is_json); break; case UPB_TYPE_MESSAGE: { #if PHP_MAJOR_VERSION < 7 diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 4107d65bb6..57b1bf1f5f 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -1135,4 +1135,17 @@ class EncodeDecodeTest extends TestBase $this->assertEquals("", $m->serializeToString()); } + public function testJsonDecodeMapWithDefaultValueKey() + { + $m = new TestMessage(); + $m->getMapInt32Int32()[0] = 0; + $this->assertSame("{\"mapInt32Int32\":{\"0\":0}}", + $m->serializeToJsonString()); + + $m = new TestMessage(); + $m->getMapStringString()[""] = ""; + $this->assertSame("{\"mapStringString\":{\"\":\"\"}}", + $m->serializeToJsonString()); + } + }