|
|
@@ -20,7 +20,7 @@ namespace json { namespace binder {
|
|
|
object_binder& operator()(std::string const&k, V T::*ptr, binder_impl<V> const&v) {
|
|
|
return (*this)(k, binder<T>(new direct_binder<T, V>(ptr, binder<V>(v) )));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
object_binder& operator()(std::string const&k, binder<T> const&v) {
|
|
|
mapping.emplace(k, v);
|
|
|
return *this;
|
|
|
@@ -53,6 +53,8 @@ namespace json { namespace binder {
|
|
|
|
|
|
void parse_object(T& object, char const*& data, parser::options opts) const {
|
|
|
std::string key;
|
|
|
+ std::set<std::string> unparsed_keys;
|
|
|
+ for ( auto & p : mapping ) { unparsed_keys.insert(p.first); }
|
|
|
while (*data && *data != '}') {
|
|
|
if (json::helper::get_next_element(data) != '"') {
|
|
|
throw json::malformed_json_exception(std::string("Expected object key starting with '\"', got '") + *data + "' instead");
|
|
|
@@ -63,6 +65,7 @@ namespace json { namespace binder {
|
|
|
}
|
|
|
auto it = mapping.find(key);
|
|
|
if (it != mapping.end()) {
|
|
|
+ unparsed_keys.erase(key);
|
|
|
it->second.parse(object, ++data, opts);
|
|
|
} else if (opts & parser::disable_unknown_keys) {
|
|
|
throw json::malformed_json_exception("Unexpected key " + key);
|
|
|
@@ -73,6 +76,9 @@ namespace json { namespace binder {
|
|
|
}
|
|
|
if (*data) ++data;
|
|
|
else throw json::unterminated_json_exception("Reached end of parse string without finding object end");
|
|
|
+ if ( !unparsed_keys.empty() && opts & parser::disable_missing_keys ) {
|
|
|
+ throw json::malformed_json_exception("missing certain keys from object construction TODO");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
template <typename E>
|