From a6afe0a60afb6763fc69f6d946b03e78ec559247 Mon Sep 17 00:00:00 2001 From: danielaparker Date: Tue, 21 Feb 2017 09:34:07 -0500 Subject: [PATCH] Fix to override with set --- src/jsoncons/json_container.hpp | 4 ++-- test_suite/src/json_object_tests.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/jsoncons/json_container.hpp b/src/jsoncons/json_container.hpp index b1ba693a9c..cd332b0704 100644 --- a/src/jsoncons/json_container.hpp +++ b/src/jsoncons/json_container.hpp @@ -1274,7 +1274,7 @@ class json_object : public Json_object_ { string_view_type s(name.data(),name.size()); auto it = std::find_if(this->members_.begin(),this->members_.end(), - [s](const value_type& a){return a.key().compare(s);}); + [s](const value_type& a){return a.key().compare(s) == 0;}); if (it == this->members_.end()) { @@ -1294,7 +1294,7 @@ class json_object : public Json_object_ { string_view_type s(name.data(),name.size()); auto it = std::find_if(this->members_.begin(),this->members_.end(), - [s](const value_type& a){return a.key().compare(s);}); + [s](const value_type& a){return a.key().compare(s) == 0;}); if (it == this->members_.end()) { diff --git a/test_suite/src/json_object_tests.cpp b/test_suite/src/json_object_tests.cpp index 7663f64ad4..488be93197 100644 --- a/test_suite/src/json_object_tests.cpp +++ b/test_suite/src/json_object_tests.cpp @@ -845,5 +845,18 @@ BOOST_AUTO_TEST_CASE(test_value_not_found_and_defaults) [](const std::exception& ex ) { return ex.what() == std::string("first_aid_certification not found"); }); } +BOOST_AUTO_TEST_CASE(test_set_override) +{ + json obj; + obj["first_name"] = "Jane"; + obj["height"] = 0.9; + + obj["first_name"] = "Joe"; + obj["height"] = "0.3"; + + BOOST_CHECK(obj["first_name"] == "Joe"); + BOOST_CHECK_CLOSE(obj["height"].as(),0.3,0.00000000001); +} + BOOST_AUTO_TEST_SUITE_END()