Skip to content

docs: clarify unknown enum string deserialization behavior#5180

Closed
leno23 wants to merge 1 commit into
nlohmann:developfrom
leno23:docs/enum-serialize-unknown-default-3992
Closed

docs: clarify unknown enum string deserialization behavior#5180
leno23 wants to merge 1 commit into
nlohmann:developfrom
leno23:docs/enum-serialize-unknown-default-3992

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 17, 2026

Summary

Document that NLOHMANN_JSON_SERIALIZE_ENUM maps unrecognized JSON strings to the first macro pair (current behavior) rather than throwing type_error, and point readers to #3992 for stricter alternatives.

Motivation

Addresses confusion raised in #3992 without changing runtime behavior while strict-macro proposals are discussed.

Test plan

  • Documentation only.

Made with Cursor

Document that unrecognized strings map to the first SERIALIZE_ENUM pair
rather than throwing, with pointer to nlohmann#3992.

- When using `get<ENUM_TYPE>()`, undefined JSON values will default to the first pair specified in your map. Select this
default pair carefully.
- **Unknown string values** that do not match any mapped string also deserialize to that same first pair—they do not
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true once #5151 is merged.

@nlohmann
Copy link
Copy Markdown
Owner

I do not like AI-generated documentation. As the behavior of enum conversion will change once #5151 is merged, this PR can be closed.

@nlohmann nlohmann closed this May 17, 2026
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