Closed GoogleCodeExporter closed 9 years ago
I noted that while snooping around in rapidjson.h that it is possible to
predefine RAPIDJSON_ASSERT, which does allow for recovery via exception
handling. Still it would be nice to have extra information about the failure,
but this is good for now.
Original comment by brian.budge@gmail.com
on 22 Feb 2012 at 10:35
By default, if error is occurred during parsing, the error status, the error
message and the byte offset of the JSON stream can be obtained via
bool GenericReader::HasParseError()
const char* GenericReader::GetParseError()
size_t GenericReader::GetErrorOffset()
and
bool GenericDocument::HasParseError() const { return parseError_ != 0; }
const char* GenericDocument::GetParseError() const { return parseError_; }
size_t GenericDocument::GetErrorOffset() const { return errorOffset_; }
Please check if they may help. Suggestion are welcome.
Original comment by milo...@gmail.com
on 28 Feb 2012 at 6:12
Yes, that's great for parsing, but I encountered this assert during file
writing after manually building a document that has null as the root value.
What might be nice is to augment RAPIDJSON_ASSERT with an informational string,
something like:
#define RAPIDJSON_ASSERT(A, B)
where A is the boolean to be checked, and B could be a const char * that gives
information about what it means when A fails.
Then, when someone predefines RAPIDJSON_ASSERT for their own app, they could
throw an exception where the what() could return that const char *. This is
only a suggestion; I'm not sure what is the best way to handle more general
information about assert failures.
Original comment by brian.budge@gmail.com
on 28 Feb 2012 at 2:32
Yes, I'm using rapidjson to validate and convert the ungodly mess that is
twitter, into protobuf. Since twitter is not well documented, and they alter
the schema from day to day I need to reverse engineer it.
I want an exception thrown when a field is absent or when a field does not have
the correct type. I could use the IsType and HasMember functions but that is
just too much code.
As brian.budge mentioned above. Explicit documentation that is flagged up
should be provided. Perhaps in the feature list on the front page, since there
is no documentation at the moment, or perhaps as an example.
Original comment by h.a.s...@gmail.com
on 4 Apr 2012 at 1:12
This is how I am using it at the moment.
namespace social_sensor
{
class rapidjson_exception : public std::runtime_error
{
public:
rapidjson_exception() : std::runtime_error("json schema invalid") {}
};
}
#define RAPIDJSON_ASSERT(x) \
if(x); \
else throw social_sensor::rapidjson_exception();
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/filewritestream.h>
Original comment by h.a.s...@gmail.com
on 4 Apr 2012 at 1:34
Original comment by milo...@gmail.com
on 14 Nov 2012 at 3:40
I converted my JSON parsing code from boost property tree to rapidjson,
improving speed and correctness (ptree does not even preserve data types,
terribly wrong path to go down, sadly). I had already included exception
handling of all malformed JSON during extraction while using ptree. Using
Hassan's approach in comment #5 worked without any need for additional code
changes. Don't forget your try() blocks though! :-)
Better docs, and rapidjson will easily take over the world! :-)
Original comment by moodb...@gmail.com
on 22 Nov 2013 at 1:06
Original comment by milo...@gmail.com
on 24 Jun 2014 at 2:05
Original issue reported on code.google.com by
brian.budge@gmail.com
on 22 Feb 2012 at 10:18