Skip to content

Commit 7d4d5ed

Browse files
committed
Fix jsoncpp deprecation warnings (Closes #312)
1 parent d5ede22 commit 7d4d5ed

File tree

7 files changed

+22
-36
lines changed

7 files changed

+22
-36
lines changed

src/jsonrpccpp/client/client.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#include "client.h"
1111
#include "rpcprotocolclient.h"
12+
#include <sstream>
1213

1314
using namespace jsonrpc;
15+
using namespace std;
1416

1517
Client::Client(IClientConnector &connector, clientVersion_t version, bool omitEndingLineFeed) : connector(connector) {
1618
this->protocol = new RpcProtocolClient(version, omitEndingLineFeed);
@@ -29,11 +31,11 @@ void Client::CallProcedures(const BatchCall &calls, BatchResponse &result) {
2931
std::string request, response;
3032
request = calls.toString();
3133
connector.SendRPCMessage(request, response);
32-
Json::Reader reader;
3334
Json::Value tmpresult;
3435

3536
try {
36-
if (!reader.parse(response, tmpresult) || !tmpresult.isArray()) {
37+
istringstream(response) >> tmpresult;
38+
if(!tmpresult.isArray()) {
3739
throw JsonRpcException(Errors::ERROR_CLIENT_INVALID_RESPONSE, "Array expected.");
3840
}
3941
} catch (const Json::Exception &e) {

src/jsonrpccpp/client/rpcprotocolclient.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ void RpcProtocolClient::BuildRequest(const std::string &method, const Json::Valu
3535
}
3636

3737
void RpcProtocolClient::HandleResponse(const std::string &response, Json::Value &result) {
38-
Json::Reader reader;
3938
Json::Value value;
4039

4140
try {
42-
if (reader.parse(response, value)) {
41+
if (std::istringstream(response) >> value) {
4342
this->HandleResponse(value, result);
4443
} else {
4544
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " " + response);

src/jsonrpccpp/common/specificationparser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ vector<Procedure> SpecificationParser::GetProceduresFromFile(const string &filen
2222
}
2323
vector<Procedure> SpecificationParser::GetProceduresFromString(const string &content) {
2424

25-
Json::Reader reader;
2625
Json::Value val;
27-
if (!reader.parse(content, val)) {
26+
27+
try {
28+
std::istringstream(content) >> val;
29+
} catch (Json::Exception &e) {
2830
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " specification file contains syntax errors");
2931
}
30-
3132
if (!val.isArray()) {
3233
throw JsonRpcException(Errors::ERROR_SERVER_PROCEDURE_SPECIFICATION_SYNTAX, " top level json value is not an array");
3334
}

src/jsonrpccpp/server/abstractprotocolhandler.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
#include "abstractprotocolhandler.h"
1111
#include <jsonrpccpp/common/errors.h>
12-
#include <jsonrpccpp/common/jsonparser.h>
13-
12+
#include <sstream>
1413
#include <map>
1514

1615
using namespace jsonrpc;
@@ -23,18 +22,14 @@ AbstractProtocolHandler::~AbstractProtocolHandler() {}
2322
void AbstractProtocolHandler::AddProcedure(const Procedure &procedure) { this->procedures[procedure.GetProcedureName()] = procedure; }
2423

2524
void AbstractProtocolHandler::HandleRequest(const std::string &request, std::string &retValue) {
26-
Json::Reader reader;
2725
Json::Value req;
2826
Json::Value resp;
2927
Json::StreamWriterBuilder wbuilder;
3028
wbuilder["indentation"] = "";
3129

3230
try {
33-
if (reader.parse(request, req, false)) {
34-
this->HandleJsonRequest(req, resp);
35-
} else {
36-
this->WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
37-
}
31+
istringstream(request) >> req;
32+
this->HandleJsonRequest(req, resp);
3833
} catch (const Json::Exception &e) {
3934
this->WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
4035
}

src/jsonrpccpp/server/rpcprotocolserver12.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <jsonrpccpp/common/jsonparser.h>
1212

1313
using namespace jsonrpc;
14+
using namespace std;
1415

1516
RpcProtocolServer12::RpcProtocolServer12(IProcedureInvokationHandler &handler) : rpc1(handler), rpc2(handler) {}
1617

@@ -20,18 +21,14 @@ void RpcProtocolServer12::AddProcedure(const Procedure &procedure) {
2021
}
2122

2223
void RpcProtocolServer12::HandleRequest(const std::string &request, std::string &retValue) {
23-
Json::Reader reader;
2424
Json::Value req;
2525
Json::Value resp;
2626
Json::StreamWriterBuilder wbuilder;
2727
wbuilder["indentation"] = "";
2828

2929
try {
30-
if (reader.parse(request, req, false)) {
31-
this->GetHandler(req).HandleJsonRequest(req, resp);
32-
} else {
33-
this->GetHandler(req).WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
34-
}
30+
istringstream(request) >> req;
31+
this->GetHandler(req).HandleJsonRequest(req, resp);
3532
} catch (const Json::Exception &e) {
3633
this->GetHandler(req).WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
3734
}

src/test/mockclientconnector.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ MockClientConnector::MockClientConnector() {}
1717
string MockClientConnector::GetRequest() { return request; }
1818

1919
Json::Value MockClientConnector::GetJsonRequest() {
20-
Json::Reader reader;
2120
Json::Value result;
22-
if (reader.parse(request, result))
23-
return result;
24-
else
25-
return Json::nullValue;
21+
std::istringstream(request) >> result;
22+
return result;
2623
}
2724

2825
void MockClientConnector::SetResponse(const std::string &response) { this->response = response; }

src/test/mockserverconnector.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
************************************************************************/
99

1010
#include "mockserverconnector.h"
11+
#include <sstream>
1112

1213
using namespace jsonrpc;
1314
using namespace std;
@@ -26,21 +27,15 @@ bool MockServerConnector::SetRequest(const string &request) {
2627
}
2728

2829
Json::Value MockServerConnector::GetJsonRequest() {
29-
Json::Reader reader;
3030
Json::Value result;
31-
if (reader.parse(request, result))
32-
return result;
33-
else
34-
return Json::nullValue;
31+
istringstream(request) >> result;
32+
return result;
3533
}
3634

3735
string MockServerConnector::GetResponse() { return this->response; }
3836

3937
Json::Value MockServerConnector::GetJsonResponse() {
40-
Json::Reader reader;
4138
Json::Value result;
42-
if (reader.parse(response, result))
43-
return result;
44-
else
45-
return Json::nullValue;
39+
istringstream(response) >> result;
40+
return result;
4641
}

0 commit comments

Comments
 (0)