Skip to content

Make JSON serialization opt-in via generateJson flag#7

Open
merlimat wants to merge 1 commit intostreamnative:masterfrom
merlimat:make-json-configurable
Open

Make JSON serialization opt-in via generateJson flag#7
merlimat wants to merge 1 commit intostreamnative:masterfrom
merlimat:make-json-configurable

Conversation

@merlimat
Copy link
Copy Markdown
Collaborator

@merlimat merlimat commented May 9, 2026

Summary

  • JSON serialization (`writeJsonTo`/`parseFromJson`/`toJson`) is now opt-in, mirroring how `generateTextFormat` already works. Default is off.
  • New `generateJson` option on the Maven plugin (boolean, default `false`) and the Gradle plugin (`LightProtoExtension` property, default `false`).
  • `writeJsonTo` and `parseFromJson` were removed from the package-private `LightProtoMessage` interface so messages compile cleanly when JSON generation is disabled. The static `LightProtoCodec.toJson(...)` helper went away — the generated `toJson()` inlines the small ByteBuf-to-String body it provided.
  • `tests/pom.xml` sets `generateJson=true` so the existing JSON tests still run.

Test plan

  • `mvn -pl tests test` — all 262 tests pass with `generateJson=true`
  • Verified default-off in a fresh test project: no `writeJsonTo` / `parseFromJson` / `toJson` / `_parseJsonObject` symbols in the generated source
  • Verified explicit-on: same JSON methods generated as before

JSON serialization (writeJsonTo/parseFromJson/toJson) was always
generated on every message, adding code size that's only useful for
projects that actually need a JSON representation. Mirror what
generateTextFormat already does and make JSON opt-in:

- New generateJson option on the Maven plugin (boolean parameter,
  default false) and the Gradle plugin (LightProtoExtension property,
  default false).
- LightProtoMessage skips generateWriteJsonTo/generateParseFromJson
  when the flag is off.
- writeJsonTo/parseFromJson removed from the LightProtoMessage
  interface so messages compile cleanly without them; the generated
  toJson() now inlines the small ByteBuf-to-String body that the
  static helper used to provide.

The tests/pom.xml sets generateJson=true so the existing JSON test
suite continues to run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant