Skip to content

fix json = json_ref - #12615

Merged
maloel merged 2 commits into
realsenseai:developmentfrom
maloel:to-json
Jan 29, 2024
Merged

fix json = json_ref#12615
maloel merged 2 commits into
realsenseai:developmentfrom
maloel:to-json

Conversation

@maloel

@maloel maloel commented Jan 28, 2024

Copy link
Copy Markdown
Contributor
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
Copy Markdown
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
Copy Markdown
Contributor 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 realsenseai:development Jan 29, 2024
@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