Convert integer to string if field is string field in json
json_decode automatically convert numeric string to integer, so that
we need to convert it back. However, this will suceed to parse invalid
json data with string field set as integer even though it should have failed.
Because, the failure case is less often than the succeeding case, we decided
to make this change. Users should make sure their data don't use integer for
string fields by themselves.
diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php
index 57b1bf1..1325db2 100644
--- a/php/tests/encode_decode_test.php
+++ b/php/tests/encode_decode_test.php
@@ -1148,4 +1148,14 @@
$m->serializeToJsonString());
}
+ public function testJsonDecodeNumericStringMapKey()
+ {
+ $m = new TestMessage();
+ $m->getMapStringString()["1"] = "1";
+ $data = $m->serializeToJsonString();
+ $this->assertSame("{\"mapStringString\":{\"1\":\"1\"}}", $data);
+ $n = new TestMessage();
+ $n->mergeFromJsonString($data);
+ }
+
}