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
Add support for null values to AnyMap #694
base: development
Are you sure you want to change the base?
Conversation
rapidjson supports null values but AnyMap did not. This change adds support for null values to the AnyMap class. Signed-off-by: The MathWorks, Inc. <pelliott@mathworks.com>
Codecov Report
@@ Coverage Diff @@
## development #694 +/- ##
===============================================
+ Coverage 90.32% 90.41% +0.08%
===============================================
Files 249 248 -1
Lines 13629 13636 +7
===============================================
+ Hits 12311 12329 +18
+ Misses 1318 1307 -11
|
Fix unused parameter warning in AnyMap.h NullValue struct. Signed-off-by: The MathWorks, Inc. <pelliott@mathworks.com>
* object allows us to save a null value in the AnyMap. | ||
*/ | ||
namespace cppmicroservices { | ||
struct NullValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a function in the Any
class to test is an Any
is NullValue
?
Currently, I don't think Any::Empty()
and Any::ToJSON()
are in alignment with this new concept of NullValue
. There might also be other Any
member functions which are not consistent with NullValue
.
/**
* returns true if the Any is empty
*/
bool Empty() const { return !_content; }
/**
* Returns a JSON representation for the content.
*
* Custom types should specialize the any_value_to_json template function for meaningful output.
* The values of increment and indent are passed around to be able to be used for nicer
* formatting. The code that makes use of this is in the any_value_to_json specializations for the
* various containers.
*
* To get pretty output, simply pass a value greater than zero in as the first argument of ToJSON
* and the rest of the code will take care of things.
*
* @param increment The amount of extra indentation to add for each level of JSON. An increment of
* zero indicates no special formatting
* @param indent The current amount of indent to apply to the current line.
*/
std::string ToJSON(const uint8_t increment, const int32_t indent) const
{
return Empty() ? "null" : _content->ToJSON(increment, indent);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think Empty should return true if the value is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that we have a user-defined type, NullValue
, representing a JSON null
, I think the answer is no.
I also think ToJSON
returning "null"
may be confusing with a ToJSON representation of JSON null
Added support to AnyMap NullValue structure to make sure functions in Any (like ToJSON and compare) work. Signed-off-by The MathWorks, Inc. <pelliott@mathworks.com>
Removed code added for debugging. Signed-off-by The MathWorks, Inc. <pelliott@mathworks.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see test coverage for NullValue
within the core framework's unit tests, i.e. within framework\test\gtest\AnyTest.cpp. Take a look at the existing tests in here for guidance on what to test. off the top of my head, testing Any::Type() for NullValue
should be done.
rapidjson supports null values but AnyMap did not. This change adds support for null values to the AnyMap class. Signed-off-by: The MathWorks, Inc. pelliott@mathworks.com