Skip to content

json: enforce repeated enum null semantics - #836

Open
vanderbr wants to merge 1 commit into
anthropics:mainfrom
reallyme:fix/repeated-enum-null
Open

vanderbr wants to merge 1 commit into
anthropics:mainfrom
reallyme:fix/repeated-enum-null

Conversation

@vanderbr

@vanderbr vanderbr commented Nov 18, 2026 •

Copy link
Copy Markdown

An ordinary repeated open enum currently accepts {"values":[null]} and silently converts the element to enum value zero. Reject null elements in both strict parsing and ignore_unknown_enum_values mode, as required by the ProtoJSON null rules. A null whole field still means an empty collection, and lenient filtering of unknown names and preservation of unknown numbers are unchanged.

A defaulted Enumeration::IS_NULL_VALUE marker preserves the explicit exception for canonical google.protobuf.NullValue input. Codegen emits it only for that exact protobuf type; an ordinary enum with a NULL_VALUE case does not qualify. Existing enum implementations continue to compile. Existing generated messages using the updated canonical WKT provider need no regeneration; external or vendored NullValue providers need regeneration or explicit metadata.

This is independent of the diagnostics work in #830 and #832. It overlaps the repeated-field portion of #806, which introduces dedicated NullValue helpers across field shapes; the generic repeated-helper changes here also support existing generated bindings. Scalar, optional and map behavior, compiler policy and dependency pins remain unchanged. Unknown enum numbers retain numeric serialization. Release preparation must advance the canonical WKT crate's minimum runtime requirement to the release containing the marker; version changes remain part of the release process.

Regression coverage includes strict/lenient parsing from JSON text and serde_json::Value, first and later null elements, same-named impostor enums, Vec/custom collections, handwritten enum implementations, the exact codegen identity boundary, owned/view parity, and frozen pre-change bindings. The ordinary-enum rejection test failed on upstream main before the fix. Checked-in WKT, option and bootstrap bindings were regenerated. Within that regeneration diff, only the canonical NullValue marker changes.

Canonical NullValue zero variants serialize as JSON null in repeated collections, including legacy generated helper calls. Closed collections accept a null element only with the explicit marker and a declared zero variant; an inconsistent handwritten marker is rejected. Other enums, unknown numbers and non-human-readable serialization preserve their behavior.

Validation:

  • Runtime and generated-fixture tests, including legacy bindings, canonical closed-enum round trips and malformed markers.
  • Strict Clippy, rustdoc and formatting; native and Rust 1.75 consumer validation.
  • The updated implementation also passes the combined upstream proposal workspace tests and strict checks.

The external protobuf conformance suite was not rerun for this follow-up.

@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Reject null elements in ordinary repeated enums in both JSON parse modes. Use explicit canonical NullValue metadata to retain valid null elements and canonical repeated output, including older generated bindings and closed collections. Preserve unknown numeric values and unrelated field behavior.
@vanderbr
vanderbr force-pushed the fix/repeated-enum-null branch from 07c7079 to 1782868 Compare November 18, 2026 23:27
@vanderbr vanderbr changed the title json: reject null elements in repeated open enums json: enforce repeated enum null semantics Nov 18, 2026

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.

1 participant