Skip to content

Fix JSON decoder exception when referencing different message’s enum - #59

Open
mbickers wants to merge 1 commit into
andersfugmann:mainfrom
mbickers:fix-json-enum-initialization
Open

Fix JSON decoder exception when referencing different message’s enum#59
mbickers wants to merge 1 commit into
andersfugmann:mainfrom
mbickers:fix-json-enum-initialization

Conversation

@mbickers

@mbickers mbickers commented Sep 7, 2026

Copy link
Copy Markdown

Defer JSON enum mapping initialization until first use to avoid an exception when a message references another message’s nested enum.

I added a regression test. Without fix, test fails with

Fatal error: exception File "test/json_enum_initialization.ml", line 126, characters 6-12: Undefined recursive module
Raised at CamlinternalMod.init_mod_field.fn in file "camlinternalMod.ml", line 30, characters 11-49
Called from Ocaml_protoc_plugin__Deserialize_json.map_enum_json in file "src/ocaml_protoc_plugin/deserialize_json.ml", line 197, characters 4-16
Called from Ocaml_protoc_plugin__Deserialize_json.read_value in file "src/ocaml_protoc_plugin/deserialize_json.ml", line 312, characters 25-52
Called from Ocaml_protoc_plugin__Deserialize_json.read in file "src/ocaml_protoc_plugin/deserialize_json.ml", line 333, characters 23-38
Called from Ocaml_protoc_plugin__Deserialize_json.deserialize in file "src/ocaml_protoc_plugin/deserialize_json.ml", line 408, characters 15-24
Called from Ocaml_protoc_plugin__Deserialize_json.deserialize in file "src/ocaml_protoc_plugin/deserialize_json.ml", line 417, characters 20-43
Called from Test__Json_enum_initialization.A.from_json_exn in file "test/json_enum_initialization.ml", line 79, characters 4-119

I hit this when working with the GTFS Realtime protocol: TripUpdate.StopTimeUpdate.departure_occupancy_status references the OccupancyStatus enum nested in VehiclePosition.

Thanks for maintaining this library!

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