Skip to content

feat: Rebase feature/optional to develop - #4036

Merged
nlohmann merged 16 commits into
nlohmann:developfrom
fsandhei:feature/optional
Nov 16, 2024
Merged

nlohmann merged 16 commits into
nlohmann:developfrom
fsandhei:feature/optional

Conversation

@fsandhei

@fsandhei fsandhei commented May 20, 2023 •

Copy link
Copy Markdown
Contributor

Rebasing feature/optional in attempt to revive this PR, referring to #2117.

Sorry for long time between responses.

I may have been going forward with this the "wrong" way, so I apologize in advance.

Please let me know if this should be handled differently.

TODO

There is one test that is failing: Conversions from a default initialized nlohmann::json to std::optional<T> seems to fail. In the test case below, the last assertion fails with an exception. This is tested on Arch Linux with GCC 13.1.1.

I was not able to figure out how to fix this so I need some assistance here.

/home/fredrik/dev/github/cpp/fredriksd/json/tests/src/unit-conversions.cpp:1573:
TEST CASE:  std::optional
  null

/home/fredrik/dev/github/cpp/fredriksd/json/tests/src/unit-conversions.cpp:1573: ERROR: test case THREW exception: exception thrown in subcase - will translate later when the whole test case has been exited (cannot translate while there is an active exception)

===============================================================================
/home/fredrik/dev/github/cpp/fredriksd/json/tests/src/unit-conversions.cpp:1573:
TEST CASE:  std::optional

DEEPEST SUBCASE STACK REACHED (DIFFERENT FROM THE CURRENT ONE):
  null

/home/fredrik/dev/github/cpp/fredriksd/json/tests/src/unit-conversions.cpp:1573: ERROR: test case THREW exception: [json.exception.type_error.302] type must be string, but is null

@fsandhei
fsandhei requested a review from nlohmann as a code owner May 20, 2023 10:12
@fsandhei fsandhei changed the title Feature/optional feat: Rebase feature/optional to develop May 20, 2023
@fsandhei fsandhei closed this May 20, 2023
@fsandhei fsandhei reopened this May 20, 2023
@fsandhei
fsandhei changed the base branch from feature/optional to develop May 20, 2023 10:43
@fsandhei

Copy link
Copy Markdown
Contributor Author

Changed the base branch to develop.

I'm sorry if I'm making it a bit difficult here; I forked the repository and rebased feature/optional to develop and created this PR against nlohmann:feature/develop but I noticed that included 590 commits (which makes sense) but it cluttered the actual change here, so I instead changed it towards nlohmann:develop.

@lightyear15

lightyear15 commented Feb 27, 2024 •

Copy link
Copy Markdown

I am also interested in having std::optional support landing in future versions of this library.
I see there was a lot of discussion on how to properly support and convert c++ optional fields vs json nullable fields.
Is there a final decision on the matter? How can we revive this PR and push forward support of std::optional fields?
@nlohmann

Comment thread include/nlohmann/detail/conversions/from_json.hpp Outdated
Comment thread tests/src/unit-conversions.cpp
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same
when pulling 1a8d427 on fsandhei:feature/optional
into 199dea1 on nlohmann:develop.

@fsandhei

fsandhei commented Apr 6, 2024

Copy link
Copy Markdown
Contributor Author

See that clang-tidy is failing on some checks. Apparently this is on develop, too. I see that it is related to a supposed new check from clang-tidy v19: https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-designated-initializers.html.

@nlohmann

nlohmann commented Apr 8, 2024

Copy link
Copy Markdown
Owner

See that clang-tidy is failing on some checks. Apparently this is on develop, too. I see that it is related to a supposed new check from clang-tidy v19: clang.llvm.org/extra/clang-tidy/checks/modernize/use-designated-initializers.html.

I'm on it. May take some more time.

@lightyear15

Copy link
Copy Markdown

has this PR stalled again?

@fsandhei

fsandhei commented May 8, 2024

Copy link
Copy Markdown
Contributor Author

I'm currently blocked by #4311.

@fsandhei

Copy link
Copy Markdown
Contributor Author

There has not been any activity in #4311 in a while. I wonder if this would be okay to merge?

@nlohmann

Copy link
Copy Markdown
Owner

Thanks for keeping this alive. I will have a look at this on Saturday.

@coveralls

coveralls commented Nov 14, 2024 •

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same
when pulling 296549c on fsandhei:feature/optional
into 1825117 on nlohmann:develop.

@fsandhei

Copy link
Copy Markdown
Contributor Author

Thanks for keeping this alive. I will have a look at this on Saturday.

Happy to help! Hopefully this can go in soon.

@nlohmann

Copy link
Copy Markdown
Owner

Please suppress the last clang-tidy warning and not change the code.

@fsandhei

Copy link
Copy Markdown
Contributor Author

Please suppress the last clang-tidy warning and not change the code.

Reverted change with 296549c.

@nlohmann nlohmann left a comment

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.

Looks good to me.

@nlohmann nlohmann added this to the Release 3.11.4 milestone Nov 16, 2024
@nlohmann
nlohmann merged commit 0604140 into nlohmann:develop Nov 16, 2024
@nlohmann

Copy link
Copy Markdown
Owner

Thanks!

@fsandhei
fsandhei deleted the feature/optional branch November 17, 2024 12:45
slowriot pushed a commit to slowriot/json that referenced this pull request Jan 10, 2025
* 🚧 conversions for std::optional

* 🏁 fix <optional> inclusion

* 💚 overwork tests

* Use JSON_HAS_CPP_17 only after it has been defined

* ✅ update tests

* 🏁 include right <optional> header

* ♻️ do not include experimental headers

* Add missing #endif after rebase

* Fix failing test

* Only define conversion to std::optional when JSON_USE_IMPLICIT_CONVERSION is disabled.

* missing endif

* Remove Wfloat-equal suppress

* amalgamate

* Move include of optional out of macro_scope; probably does not make sense to be there

* Make clang-tidy happy

* Suppress lint instead of changing to 'contains'

---------

Co-authored-by: Niels Lohmann <mail@nlohmann.me>
Co-authored-by: Markus Palonen <markus.palonen@gmail.com>
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.

[C++17] Allow std::optional to convert to nlohmann::json

5 participants