Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java JsonFormat.printer().preservingProtoFieldNames() incompatible with Python google.protobuf.json_format.Parse() #2029

Closed
fryingpanjoe opened this issue Aug 30, 2016 · 3 comments

Comments

@fryingpanjoe
Copy link

Yo!

Using JsonFormat.printer().preservingProtoFieldNames() to serialize Protobuf to JSON in Java can make the result incompatible with Python's google.protobuf.json_format.Parse().

Example:

// test.proto
syntax = "proto2";
message Test {
  optional int32 under_score = 1;
}
# test.py
import test_pb2
import google.protobuf.json_format
google.protobuf.json_format.Parse('{"under_score":1}', test_pb2.Test())

The Java code will generate the following JSON:

{
    "under_score": 1
}

while the Python parser expects the following JSON:

{
    "underScore": 1
}

which results in the following error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    google.protobuf.json_format.Parse('{"under_score":1}', test_pb2.Test())
  File "/usr/local/lib/python2.7/site-packages/google/protobuf/json_format.py", line 332, in Parse
    parser.ConvertMessage(js, message)
  File "/usr/local/lib/python2.7/site-packages/google/protobuf/json_format.py", line 363, in ConvertMessage
    self._ConvertFieldValuePair(value, message)
  File "/usr/local/lib/python2.7/site-packages/google/protobuf/json_format.py", line 441, in _ConvertFieldValuePair
    raise ParseError(str(e))
google.protobuf.json_format.ParseError: Message type "Test" has no field named "under_score".
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Aug 30, 2016

This is a known issue in python JSON support. We already fixed it in our internal code base but it won't be included in opensource util next minor release (version 3.1.x).

@fryingpanjoe
Copy link
Author

Fantabulous, thank you!

@acozzette
Copy link
Member

Let me close this because I believe it has been fixed now; if it's still a problem feel free to reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants