Skip to content

fix: skip map entries with unknown enum values in Moshi and Gson JSON - #3832

Merged
oldergod merged 1 commit into
square:masterfrom
pcbeingused33:fix/json-map-unknown-enum
Nov 30, 2026
Merged

oldergod merged 1 commit into
square:masterfrom
pcbeingused33:fix/json-map-unknown-enum

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Related to #3508 (the repeated-field part is already handled).

The Moshi and Gson adapters ignore unrecognized enum constants in repeated fields, but reject a whole message when a map<K, Enum> field holds one:

{"mapStringEnum":{"a":"A","b":"NOT_A_CONSTANT"}}
-> JsonDataException / JsonSyntaxException: expected a map value that is not null

Cause: EnumJsonFormatter returns null for an unknown constant. JsonIntegration passes skipNull to listAdapter for enum elements, but mapAdapter had no equivalent, so the map adapters treated the value as a null.

Fix: pass skipNull to mapAdapter too and skip the entry. This follows the repeated-field behavior, and is close to the binary decoder since #3785, which also keeps such an entry out of the map. An explicit JSON null map value is still rejected, as are null values in non-enum maps.

Tests: two cases in WireJsonTest. The unknown-value case fails for all six Moshi/Gson variants without the fix and passes with it; the explicit-null case covers the behavior that stays.

Prepared with AI assistance.

@oldergod

Copy link
Copy Markdown
Member

Thank you

@oldergod
oldergod enabled auto-merge November 30, 2026 13:43
@oldergod
oldergod merged commit e8941e3 into square:master Nov 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants