From 4ac92e5cb27e726a1fc02d1c086bf23122eeda84 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jun 2015 09:28:00 -0500 Subject: [PATCH] JSON Stringifier fails with preserve insert order #819 --- JSON/include/Poco/JSON/Object.h | 14 +++++++------- JSON/src/Object.cpp | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/JSON/include/Poco/JSON/Object.h b/JSON/include/Poco/JSON/Object.h index e2386c0c5..b85bce8ad 100644 --- a/JSON/include/Poco/JSON/Object.h +++ b/JSON/include/Poco/JSON/Object.h @@ -239,16 +239,16 @@ private: out << '}'; } - typedef std::deque KeyPtrList; - typedef Poco::DynamicStruct::Ptr StructPtr; + typedef std::deque KeyList; + typedef Poco::DynamicStruct::Ptr StructPtr; const std::string& getKey(ValueMap::const_iterator& it) const; const Dynamic::Var& getValue(ValueMap::const_iterator& it) const; - const std::string& getKey(KeyPtrList::const_iterator& it) const; - const Dynamic::Var& getValue(KeyPtrList::const_iterator& it) const; + const std::string& getKey(KeyList::const_iterator& it) const; + const Dynamic::Var& getValue(KeyList::const_iterator& it) const; ValueMap _values; - KeyPtrList _keys; + KeyList _keys; bool _preserveInsOrder; mutable StructPtr _pStruct; }; @@ -318,9 +318,9 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const } -inline const Dynamic::Var& Object::getValue(KeyPtrList::const_iterator& it) const +inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const { - return **it; + return _values.at(*it); } diff --git a/JSON/src/Object.cpp b/JSON/src/Object.cpp index a22bf0b61..7531c73a0 100644 --- a/JSON/src/Object.cpp +++ b/JSON/src/Object.cpp @@ -101,16 +101,16 @@ void Object::stringify(std::ostream& out, unsigned int indent, int step) const } -const std::string& Object::getKey(KeyPtrList::const_iterator& iter) const +const std::string& Object::getKey(KeyList::const_iterator& iter) const { ValueMap::const_iterator it = _values.begin(); ValueMap::const_iterator end = _values.end(); for (; it != end; ++it) { - if (it->second == **iter) return it->first; + if (it->first == *iter) return it->first; } - throw NotFoundException((*iter)->convert()); + throw NotFoundException(*iter); } @@ -119,13 +119,13 @@ void Object::set(const std::string& key, const Dynamic::Var& value) _values[key] = value; if (_preserveInsOrder) { - KeyPtrList::iterator it = _keys.begin(); - KeyPtrList::iterator end = _keys.end(); + KeyList::iterator it = _keys.begin(); + KeyList::iterator end = _keys.end(); for (; it != end; ++it) { - if (key == **it) return; + if (key == *it) return; } - _keys.push_back(&_values[key]); + _keys.push_back(key); } }