Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally accept arbitrary root elements #17

Closed
wants to merge 4 commits into from

Conversation

pah
Copy link
Contributor

@pah pah commented Jun 25, 2014

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<FileStream> 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

pah added 4 commits June 25, 2014 14:15
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.
And consistently add documentation to all AcceptAnyRoot()
functions.
@pah
Copy link
Contributor Author

pah commented Jun 25, 2014

Closing, to be resubmitted against master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant