protocolbuffers / protocolbuffers/protobuf
Java JSON serializer emits invalid extension keys by default
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 72k
- Forks
- 16.3k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 140
Description
The Java JSON serializer emits extensions using their short names here:
https://github.com/protocolbuffers/protobuf/blob/382f6a7eaf00f120afbc800723af7d67dd06ab63/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java#L1175
For example, an extension foo.bar will be emitted as "bar": "value" instead of "[foo.bar]": "value".
The resulting JSON is unparseable in any language, unless the extension's short name happens to clash with another field name. In that case it will result in silent data corruption. It can also lead to JSON with duplicate keys (i.e. data loss) if two extensions have the same short name.
As of 35.0 this has a fix that can be opted into by calling printingFullyQualifiedExtensionNames(). But it can't be enabled by default without a breaking change
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at java/util/src/main/java/com/google/protobuf/util/JsonFormat.java around line 1175 and compare the default extension-name path with printingFullyQualifiedExtensionNames(). Determine the compatible resolution for invalid or duplicate keys, then verify that extension serialization and parsing behavior remain consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100