miloyip/rapidjson — pull request #17 by pah (2014-06-25 12:29:02+00:00)
Title: Optionally accept arbitrary root elements

Although RFC 4627 requires root elements to be either an object or an array,
sometimes the plain (de)serialisation of an arbitrary value is needed.

This pull-request adds a new function `AcceptAnyRoot(bool)` to
* `GenericReader`
* `GenericDocument`
* `(Pretty)Writer`

to optionally accept such arbitrary root elements for reading/parsing and writing.

Example:
````
{
Document d;
d.AcceptAnyRoot().Parse<0>( "\"foo\"" );
assert(!d.HasParseError());
assert(d.IsString());

FileStream s(stdout);
PrettyWriter writer(s);
d.Accept( writer.AcceptAnyRoot() );
}
````
This functionality is guarded behind the preprocessor symbol `RAPIDJSON_ACCEPT_ANY_ROOT`.

Additional unit tests are added in `acceptanyroot.cpp` as well.
See Google code issue http://code.google.com/p/rapidjson/issues/detail?id=98