Skip to content

fix required member check for described structs in parse_into - #1182

Open
Ramya-9353 wants to merge 4 commits into
boostorg:developfrom
Ramya-9353:parse-into-required-members
Open

fix required member check for described structs in parse_into#1182
Ramya-9353 wants to merge 4 commits into
boostorg:developfrom
Ramya-9353:parse-into-required-members

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: parse_into a described struct whose members are all required, from {"a": 1, "a": 2, "a": 3}. It reports success, and b and c keep whatever the caller's object held. Same for {"a": 2} as the second element of [{"a": 1, "b": 1, "c": "one"}, {"a": 2}] parsed into std::vector<X>.
Cause: activated_ counts values signalled rather than distinct members, and is never cleared, so a repeated key stands in for a missing one, and each object in a sequence starts from the previous object's count.
Fix: record which members have been set, and clear that record in on_object_begin, the way the sequence handler already clears its container in on_array_begin.

@cppalliance-bot

cppalliance-bot commented Aug 6, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1182.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-08-13 06:48:59 UTC

@cppalliance-bot

cppalliance-bot commented Aug 6, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://1182.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1182.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1182.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-08-13 07:00:22 UTC

@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

I will have to think a bit about this one. I'm not sure we should check for this, because non-unique keys are explicitly discouraged by the RFC. On the other hand, I see the value this adds.

Comment thread include/boost/json/detail/parse_into.hpp Outdated
@Ramya-9353

Copy link
Copy Markdown
Contributor Author

On the RFC point: fair, though the patch does not actually reject duplicate keys as such. A document with repeated keys still parses so long as every required member is supplied somewhere; a repeat just no longer counts as a second distinct member. The other half of the bug also triggers with entirely unique keys: [{"a": 1, "b": 1, "c": "one"}, {"a": 2}] into std::vector<X> was accepted with the second element's b and c never written, because activated_ carried over the first object's count. Same carryover reaches map values and nested struct members.

@cppalliance-bot

Copy link
Copy Markdown

Comment thread include/boost/json/detail/parse_into.hpp Outdated
Comment thread include/boost/json/detail/parse_into.hpp Outdated
@cppalliance-bot

Copy link
Copy Markdown

@grisumbras

Copy link
Copy Markdown
Member

Also, please rebase on current develop, so that CI stops failing.

@Ramya-9353
Ramya-9353 force-pushed the parse-into-required-members branch from bff5000 to 9e9458f Compare August 13, 2026 06:41
@Ramya-9353

Copy link
Copy Markdown
Contributor Author

Rebased onto current develop.

@cppalliance-bot

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.91%. Comparing base (bac1ab9) to head (9e9458f).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1182   +/-   ##
========================================
  Coverage    93.91%   93.91%           
========================================
  Files           91       91           
  Lines         9288     9290    +2     
========================================
+ Hits          8723     8725    +2     
  Misses         565      565           
Files with missing lines Coverage Δ
include/boost/json/detail/parse_into.hpp 99.33% <100.00%> (+<0.01%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bac1ab9...9e9458f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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