Support root arrays in JSONInput

If a root array '[13, 14, 15]' is given to the JSONInput it will fail to
parse it because it is expecting an object. Root arrays are conformable to
the old JSON specification that the version of RapidJSON cereal uses
implements
This commit is contained in:
Matt Clarkson
2015-09-22 15:03:24 +01:00
parent 608d48d7b8
commit 2c0451d647
+8 -2
View File
@@ -414,7 +414,10 @@ namespace cereal
itsReadStream(stream)
{
itsDocument.ParseStream<0>(itsReadStream);
itsIteratorStack.emplace_back(itsDocument.MemberBegin(), itsDocument.MemberEnd());
if (itsDocument.IsArray())
itsIteratorStack.emplace_back(itsDocument.Begin(), itsDocument.End());
else
itsIteratorStack.emplace_back(itsDocument.MemberBegin(), itsDocument.MemberEnd());
}
//! Loads some binary data, encoded as a base64 string
@@ -685,7 +688,10 @@ namespace cereal
//! Loads the size for a SizeTag
void loadSize(size_type & size)
{
size = (itsIteratorStack.rbegin() + 1)->value().Size();
if (itsIteratorStack.size() == 1)
size = itsDocument.Size();
else
size = (itsIteratorStack.rbegin() + 1)->value().Size();
}
//! @}