json2pb
json2pb copied to clipboard
Fixed json serialization for 'bytes' field - value base64 encoded with extra newline
Notice that for json2pb.py, using test.proto, the value for '_bin' field is incorrectly serialized into '0a0a0a0a\n' after doing json->pb->json.
As shown in http://bugs.python.org/issue17714, python str.encode() with 'base64' as argument adds a trailing new line character to the returned string. This causes the bug in json2pb.py when handling bytes field.
- Replaced str.encode('base64') with base64.b64encode(str).
- Added a unit test for json2pb.py. Test case 'test_bytes_base64' shall fail without the fix.