wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Enhancement: optionally accept arbitrary root elements #98

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

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 patch 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<FileStream> writer(s);
  d.Accept( writer.AcceptAnyRoot() );
}

This functionality is guarded behind the preprocessor symbol
RAPIDJSON_ACCEPT_ANY_ROOT.

A patch implementing this feature can be found in my GitHub fork at
https://github.com/pah/rapidjson/commit/1026b837
(simply append .patch or .diff to download as raw).

This patch assumes that issue #72 is fixed as well
(see https://github.com/pah/rapidjson/commit/056a14e61).

Original issue reported on code.google.com by philipp....@gmail.com on 1 Feb 2014 at 7:09

GoogleCodeExporter commented 9 years ago
I have now created an explicit pull-request against the current Subversion 
trunk (mirror) to track the "evolution" of this issue in my GitHub fork as well.

Pull-request: https://github.com/pah/rapidjson/pull/4
Latest patch: https://github.com/pah/rapidjson/pull/4.diff

In the current version of the patch, explicit unit tests are now added as well.

Original comment by philipp....@gmail.com on 2 Apr 2014 at 4:02

GoogleCodeExporter commented 9 years ago

Original comment by milo...@gmail.com on 30 Jun 2014 at 5:06

GoogleCodeExporter commented 9 years ago
A general discussion on strict/relaxed syntax of JSON is issued here.
https://github.com/miloyip/rapidjson/issues/36

Original comment by milo...@gmail.com on 2 Jul 2014 at 1:30

GoogleCodeExporter commented 9 years ago

Original comment by milo...@gmail.com on 13 Jul 2014 at 4:42