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

Remove RapidJson warning when building #1876

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/acorn/app/models/squirrel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,21 @@ inline void Squirrel::serialize(rapidjson::Writer<rapidjson::StringBuffer>& writ
writer.EndObject();
}

inline bool Squirrel::deserialize(const rapidjson::Document& doc) {
inline bool Squirrel::deserialize(const rapidjson::Document& doc)
{
if(not (doc.HasMember("name") and doc["name"].IsString()))
return false;

if(not (doc.HasMember("age") and doc["age"].IsInt()))
return false;

if(not (doc.HasMember("occupation") and doc["occupation"].IsString()))
return false;

name_ = doc["name"].GetString();
age_ = doc["age"].GetUint();
occupation_ = doc["occupation"].GetString();

return true;
}

Expand Down
12 changes: 7 additions & 5 deletions examples/acorn/app/routes/squirrels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ class Squirrels : public mana::Router {
// create an empty model
acorn::Squirrel s;
// deserialize it
s.deserialize(doc);
bool ok = s.deserialize(doc);
if(UNLIKELY(not ok))
{
printf("[Squirrels@POST:/] Could not deserialize squirrel\n");
res->error({"Parsing Error", "Could not parse data."});
return;
}
// add to bucket
auto id = squirrels->capture(s);
assert(id == s.key);
Expand All @@ -74,10 +80,6 @@ class Squirrels : public mana::Router {
// send the created entity as response
res->send_json(s.json());
}
catch(const Assert_error& e) {
printf("[Squirrels@POST:/] Assert_error: %s\n", e.what());
res->error({"Parsing Error", "Could not parse data."});
}
catch(const bucket::ConstraintException& e) {
printf("[Squirrels@POST:/] ConstraintException: %s\n", e.what());
res->error({"Constraint Exception", e.what()});
Expand Down
14 changes: 0 additions & 14 deletions lib/mana/include/mana/attributes/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@
#define RAPIDJSON_THROWPARSEEXCEPTION 1
#endif

#include <stdexcept>
/**
*
*/
namespace mana {

struct Assert_error : public std::logic_error {
using std::logic_error::logic_error;
}; //< struct Assert_error

} // < namespace mana

#define RAPIDJSON_ASSERT(x) if (!(x)) throw mana::Assert_error(RAPIDJSON_STRINGIFY(x))

#include <mana/attribute.hpp>
#include <rapidjson/writer.h>
#include <rapidjson/document.h>
Expand Down
18 changes: 7 additions & 11 deletions lib/mana/src/middleware/parsley.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ void Parsley::process(mana::Request_ptr req, mana::Response_ptr, mana::Next next
auto json = std::make_shared<attribute::Json_doc>();

// Access the document and parse the body
try {
json->doc().Parse(req->source().body().data());
#ifdef VERBOSE_WEBSERVER
printf("<Parsley> Parsed JSON data.\n");
#endif
bool err = json->doc().Parse(req->source().body().data()).HasParseError();
#ifdef VERBOSE_WEBSERVER
printf("<Parsley> Parsed JSON data.\n");
#endif

// Add the json attribute to the request
if(not err)
req->set_attribute(std::move(json));
}
catch(const Assert_error& e) {
printf("<Parsley> Parsing error.\n");
}

else
printf("<Parsley> Parsing error\n");
}

return (*next)();
Expand Down
2 changes: 1 addition & 1 deletion mod/rapidjson