Skip to content

Support bool map keys in Moshi and Gson JSON adapters - #3733

Open
sebxt wants to merge 1 commit into
square:masterfrom
sebxt:fix/json-bool-map-keys
Open

sebxt wants to merge 1 commit into
square:masterfrom
sebxt:fix/json-bool-map-keys

Conversation

@sebxt

@sebxt sebxt commented Oct 19, 2026

Copy link
Copy Markdown

JsonIntegration.mapKeyJsonFormatter() had no case for ProtoAdapter.BOOL, so creating a Moshi or Gson adapter for any message with a map<bool, V> field threw IllegalStateException: Unexpected map key type: class kotlin.Boolean.

This adds a formatter that writes bool keys as "true" and "false", as the proto3 JSON mapping specifies, and parses them back. Other strings are rejected.

Test: added a MapBoolKeys message to the shared map_types.proto fixture and a mapBoolKeys case to WireJsonTest, which runs against the Kotlin and Java generated code for every Moshi and Gson configuration. It fails without the change and passes with it.

Fixes #3732

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
@oldergod

Copy link
Copy Markdown
Member

Thank you for contributing. Once you signed our CLA, I'll merge the PR.

This branch has not been deployed

No deployments
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.

Moshi and Gson JSON adapters fail for messages with a map<bool, V> field

2 participants