Hi Chris,
ScalaPB's JsonFormat goal is to follow the
JSON spec and otherwise the behavior of the Java protobuf library. In that sense, discarding unknown fields is the correct and intended behavior. From the
API docs:
Proto2 only features (e.g., extensions and unknown fields) will be discarded in the conversion. That is, when converting proto2 messages to JSON format, extensions and unknown fields will be treated as if they do not exist. This applies to proto2 messages embedded in proto3 messages as well.
Since the above comment was written, unknown fields became available in proto3 (it's no longer a proto2-only feature), yet the official JSON serializer/parser ignores them.
One way to solve this would be to add an option to the parser/serializer to encode the unknown fields as a base64 string under an "_unknownFields" key in the json object. This would make it possible to pass those bits around without the JSON library knowing their interpretation, though it wouldn't be human readable. Let me know if something like this can be useful, and feel free to file a feature request in scalapb-json4s github project for that. It will be helpful if you can indicate whether you're available to work on a PR to expedite this.
I would also strongly recommend that if both systems use proto, consider using the binary representation and not the JSON representation, as you are missing out on protocol evolution features of protobuf. These features include properly preserving unknown fields, supporting field renames (as long as the type and tag number are the same), unrecognized enum values, and so on.