Skip to content

Conversation

@efer-ms
Copy link

@efer-ms efer-ms commented Sep 24, 2025

This adds an option to ignore unknown enum variants on deserialization. This allows for better forward compatibility, as decoding JSON with newer enum values no longer fails, but instead defaults the enum values (typically set to UNSPECIFIED/UNKNOWN).

Add a test feature and tests specifically around this feature.

The related issue: #92

@xnorpx
Copy link

xnorpx commented Nov 19, 2025

@crepererum anything more needed for this eventually get merged?

@crepererum
Copy link
Contributor

Sorry, I wasn't paying attention. Code looks good, could we extend CI to also test this feature here:

pbjson/.circleci/config.yml

Lines 123 to 145 in d067f2e

steps:
- checkout
- rust_components
- cache_restore
- run:
name: Cargo test
command: cargo test --workspace
- run:
name: Cargo test (ignore unknown fields)
command: cargo test --workspace --features ignore-unknown-fields
- run:
name: Cargo test (btree)
command: cargo test --workspace --features btree
- run:
name: Cargo test (emit fields)
command: cargo test --workspace --features emit-fields
- run:
name: Cargo test (use integers for enums)
command: cargo test --workspace --features use-integers-for-enums
- run:
name: Cargo test (preserve proto field names)
command: cargo test --workspace --features preserve-proto-field-names
- cache_save

@efer-ms
Copy link
Author

efer-ms commented Nov 19, 2025

Sorry, I wasn't paying attention. Code looks good, could we extend CI to also test this feature here:

pbjson/.circleci/config.yml

Lines 123 to 145 in d067f2e

steps:
- checkout
- rust_components
- cache_restore
- run:
name: Cargo test
command: cargo test --workspace
- run:
name: Cargo test (ignore unknown fields)
command: cargo test --workspace --features ignore-unknown-fields
- run:
name: Cargo test (btree)
command: cargo test --workspace --features btree
- run:
name: Cargo test (emit fields)
command: cargo test --workspace --features emit-fields
- run:
name: Cargo test (use integers for enums)
command: cargo test --workspace --features use-integers-for-enums
- run:
name: Cargo test (preserve proto field names)
command: cargo test --workspace --features preserve-proto-field-names
- cache_save

Done

@xnorpx
Copy link

xnorpx commented Nov 20, 2025

@crepererum can you approve workflow and see if this is good?

feat: add ignore_unknown_enum_variants feature

Enabling this feature adjust deserialization to ignore unknown enum variants rather than Err out. This permits similar behavior to binary protobuf deserialization and greater backwards/forward compat. of the serialized messages.
@efer-ms efer-ms force-pushed the efer/ignore_unknown_enum_variants branch from f9e4bf5 to 2d7cf0e Compare November 20, 2025 15:51
@efer-ms efer-ms changed the title Add ignore_unknown_enum_variants feat: add ignore_unknown_enum_variants Nov 20, 2025
@efer-ms
Copy link
Author

efer-ms commented Nov 20, 2025

@crepererum , rewrote commits to match sematic conventions (I think). So it'd need another run.

@crepererum
Copy link
Contributor

Can you rebase against main again? Sorry, our CI kinda broke and I've fixed it in #149.

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.

3 participants