Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json = json_ref #12615

Merged
merged 2 commits into from
Jan 29, 2024
Merged

fix json = json_ref #12615

merged 2 commits into from
Jan 29, 2024

Conversation

maloel
Copy link
Collaborator

@maloel maloel commented Jan 28, 2024

json j = j2.nested( "subkey" );

This didn't work... :(

The nesting returns a json_ref, correctly.

operator=() gets called. But the implementation is a copy-and-swap one, meaning it attempts to construct a json value from the argument. Since the argument isn't a json object (doesn't matter that it has a conversion operator), it does this by attempting to deserialize it with to_json()!

Can also be fixed by:

json j = j2.nested( "subkey" ).get_json();

But this requires handling at every usage.
So we provide a simple to_json() implementation...

Related to #12555.

@maloel maloel requested a review from OhadMeir January 28, 2024 09:05
@maloel maloel added the bug label Jan 28, 2024
// operator=() get called. But the implementation is a copy-and-swap one, meaning it attempts to construct a json value
// from the argument. Since the argument isn't a json object (doesn't matter that it has a conversion operator), it does
// this by attempting to deserialize it with to_json()! We need to avoid this, for this usage and others...
inline void to_json( rsutils::json & j, json_ref const & jr )
Copy link
Contributor

Choose a reason for hiding this comment

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

This gets called automatically by the json constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, they have a constructor to take any unknown type and convert it to json. It does this via to_json.

@maloel maloel merged commit a71b269 into IntelRealSense:development Jan 29, 2024
17 checks passed
@maloel maloel deleted the to-json branch January 29, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants