Document Python & PHP non-conformance where booleans are accepted by int and float fields.

PiperOrigin-RevId: 952905948
This commit is contained in:
Tony Liao 2026-07-23 12:50:10 -07:00 committed by Copybara-Service
parent 6a31b747f2
commit cb440834fd
6 changed files with 56 additions and 0 deletions

View file

@ -1982,6 +1982,16 @@ class JsonFormatTest(JsonFormatBase):
{'armor': 1},
)
def testParseBooleanInputForEnum(self):
# In Python, bool is a subclass of int (int(True) == 1). We document that
# JSON boolean literals like 'true' are accepted for enum fields and coerced
# to integer enum values.
msg = json_enumval_custom_string_pb2.Knight()
json_format.Parse('{"armor": true}', msg)
self.assertEqual(
msg.armor, json_enumval_custom_string_pb2.Armor.ARMOR_GREAT_HELM
)
if __name__ == '__main__':
unittest.main()