You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/07/06 04:45:39 UTC
[2/4] mesos git commit: Updated JSON::Value.find to return None when
a Null is found.
Updated JSON::Value.find to return None when a Null is found.
Review: https://reviews.apache.org/r/49670
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/741fcb30
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/741fcb30
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/741fcb30
Branch: refs/heads/master
Commit: 741fcb305b68d00b89f9d205af43a0fe204dbea9
Parents: 516d8ef
Author: Benjamin Mahler <bm...@apache.org>
Authored: Tue Jul 5 16:03:27 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Jul 5 21:35:56 2016 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/json.hpp | 16 +++++++++++++---
3rdparty/stout/tests/json_tests.cpp | 21 +++++++++++++++++----
2 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/741fcb30/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/json.hpp b/3rdparty/stout/include/stout/json.hpp
index 829838b..fde15fa 100644
--- a/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/stout/include/stout/json.hpp
@@ -160,6 +160,11 @@ struct Object
// within a field called 'nested' of 'object' (where 'nested' must
// also be a JSON object).
//
+ // For 'null' field values, this will return 'Some(Null())' when
+ // looking for a matching type ('Null' or 'Value'). If looking for
+ // any other type (e.g. 'String', 'Object', etc), this will return
+ // 'None' as if the field is not present at all.
+ //
// Returns an error if a JSON value of the wrong type is found, or
// an intermediate JSON value is not an object that we can do a
// recursive find on.
@@ -394,12 +399,17 @@ Result<T> Object::find(const std::string& path) const
}
if (names.size() == 1) {
- if (!value.is<T>()) {
+ if (value.is<T>()) {
+ return value.as<T>();
+ } else if (value.is<Null>()) {
+ return None();
+ } else {
// TODO(benh): Use a visitor to print out the type found.
return Error("Found JSON value of wrong type");
}
- return value.as<T>();
- } else if (!value.is<Object>()) {
+ }
+
+ if (!value.is<Object>()) {
// TODO(benh): Use a visitor to print out the intermediate type.
return Error("Intermediate JSON value not an object");
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/741fcb30/3rdparty/stout/tests/json_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/json_tests.cpp b/3rdparty/stout/tests/json_tests.cpp
index 12eaf8e..a6f7da5 100644
--- a/3rdparty/stout/tests/json_tests.cpp
+++ b/3rdparty/stout/tests/json_tests.cpp
@@ -313,10 +313,6 @@ TEST(JsonTest, Find)
object.find<JSON::Number>("nested1.nested2.double"));
ASSERT_SOME_EQ(
- JSON::Null(),
- object.find<JSON::Null>("nested1.nested2.null"));
-
- ASSERT_SOME_EQ(
JSON::String("hello"),
object.find<JSON::String>("nested1.nested2.array[0]"));
@@ -337,6 +333,23 @@ TEST(JsonTest, Find)
// Out of bounds is none.
ASSERT_NONE(object.find<JSON::String>("nested1.nested2.array[1]"));
+ // Null entries are found when looking for a matching type (Null or Value).
+ ASSERT_SOME_EQ(
+ JSON::Null(),
+ object.find<JSON::Null>("nested1.nested2.null"));
+ ASSERT_SOME_EQ(
+ JSON::Null(),
+ object.find<JSON::Value>("nested1.nested2.null"));
+
+ // Null entries are not found when looking for non-null finds.
+ ASSERT_NONE(object.find<JSON::String>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::Number>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::Object>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::Array>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::True>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::False>("nested1.nested2.null"));
+ ASSERT_NONE(object.find<JSON::Boolean>("nested1.nested2.null"));
+
// Also test getting JSON::Value when you don't know the type.
ASSERT_SOME(object.find<JSON::Value>("nested1.nested2.null"));
}