protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.64k stars 15.49k forks source link

PHP FieldMasks json serialization is inconsistent for empty object #4734

Closed michaelbausor closed 5 years ago

michaelbausor commented 6 years ago

An empty FieldMask is serialized to "", but this does not deserialize to an empty FieldMask object. This PHPUnit test fails:

public function testJsonEquality()
{
  $fm = new FieldMask();
  $json = $fm->serializeToJsonString();
  $fm2 = new FieldMask();
  $fm2->mergeFromJsonString($json);
  $this->assertEquals($fm, $fm2);
}
TeBoring commented 6 years ago

I'll fix it.

TeBoring commented 5 years ago

There is an ambiguity in FieldMask: both {} and {"path":""} (in text format) have the json representation of "". Because {"path":""} is actually an invalid FieldMask, we have decided the decoded result of "" should be {} (in text format).