• Leon Barrett's avatar
    Fix parsing empty Struct Values from Json (#5211) · 9e69594a
    Leon Barrett authored
    * Fix parsing empty Struct Values from Json
    
    This fixes a bug. When parsing a struct from JSON like
        struct = json_format.Parse('{"k": {}}', Struct())
    then the struct's "k" value would end up not initialized, and accessing
    the value would raise an error.
        In[1]: struct['k']
        ValueError: Value not set
    That seems to be because the Struct field of the Value was not set.
        In[2]: struct
        Out[2]:
        fields {
          key: "k"
          value {
          }
        }
    
    This commit makes sure that the Value's Struct field is initialized even
    if the Struct has no values itself.
    
    This commit also extends a test to cover this case.
    
    * Additionally test for empty list
    9e69594a
Name
Last commit
Last update
..
protobuf Loading commit data...
__init__.py Loading commit data...