Skip to content

Commit 4ac92e5

Browse files
author
unknown
committed
JSON Stringifier fails with preserve insert order pocoproject#819
1 parent 375eca2 commit 4ac92e5

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎JSON/include/Poco/JSON/Object.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ class JSON_API Object
239239
out << '}';
240240
}
241241

242-
typedef std::deque<Dynamic::Var*> KeyPtrList;
243-
typedef Poco::DynamicStruct::Ptr StructPtr;
242+
typedef std::deque<std::string> KeyList;
243+
typedef Poco::DynamicStruct::Ptr StructPtr;
244244

245245
const std::string& getKey(ValueMap::const_iterator& it) const;
246246
const Dynamic::Var& getValue(ValueMap::const_iterator& it) const;
247-
const std::string& getKey(KeyPtrList::const_iterator& it) const;
248-
const Dynamic::Var& getValue(KeyPtrList::const_iterator& it) const;
247+
const std::string& getKey(KeyList::const_iterator& it) const;
248+
const Dynamic::Var& getValue(KeyList::const_iterator& it) const;
249249

250250
ValueMap _values;
251-
KeyPtrList _keys;
251+
KeyList _keys;
252252
bool _preserveInsOrder;
253253
mutable StructPtr _pStruct;
254254
};
@@ -318,9 +318,9 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const
318318
}
319319

320320

321-
inline const Dynamic::Var& Object::getValue(KeyPtrList::const_iterator& it) const
321+
inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const
322322
{
323-
return **it;
323+
return _values.at(*it);
324324
}
325325

326326

‎JSON/src/Object.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ void Object::stringify(std::ostream& out, unsigned int indent, int step) const
101101
}
102102

103103

104-
const std::string& Object::getKey(KeyPtrList::const_iterator& iter) const
104+
const std::string& Object::getKey(KeyList::const_iterator& iter) const
105105
{
106106
ValueMap::const_iterator it = _values.begin();
107107
ValueMap::const_iterator end = _values.end();
108108
for (; it != end; ++it)
109109
{
110-
if (it->second == **iter) return it->first;
110+
if (it->first == *iter) return it->first;
111111
}
112112

113-
throw NotFoundException((*iter)->convert<std::string>());
113+
throw NotFoundException(*iter);
114114
}
115115

116116

@@ -119,13 +119,13 @@ void Object::set(const std::string& key, const Dynamic::Var& value)
119119
_values[key] = value;
120120
if (_preserveInsOrder)
121121
{
122-
KeyPtrList::iterator it = _keys.begin();
123-
KeyPtrList::iterator end = _keys.end();
122+
KeyList::iterator it = _keys.begin();
123+
KeyList::iterator end = _keys.end();
124124
for (; it != end; ++it)
125125
{
126-
if (key == **it) return;
126+
if (key == *it) return;
127127
}
128-
_keys.push_back(&_values[key]);
128+
_keys.push_back(key);
129129
}
130130
}
131131

0 commit comments

Comments
 (0)