Skip to content

Commit 6953cd2

Browse files
authored
Merge pull request #110 from c-jimenez/fix/stop_transaction_without_reason
[stoptransaction] Make 'reason' field optional
2 parents 135b503 + 22033c1 commit 6953cd2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/messages/StopTransaction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ bool StopTransactionReqConverter::fromJson(const rapidjson::Value& json,
5656
extract(json, "meterStop", data.meterStop);
5757
bool ret = extract(json, "timestamp", data.timestamp, error_message);
5858
extract(json, "transactionId", data.transactionId);
59-
data.reason = ReasonHelper.fromString(json["reason"].GetString());
59+
if (json.HasMember("reason"))
60+
{
61+
data.reason = ReasonHelper.fromString(json["reason"].GetString());
62+
}
6063
if (json.HasMember("transactionData"))
6164
{
6265
const rapidjson::Value& transactionData = json["transactionData"];
@@ -83,7 +86,10 @@ bool StopTransactionReqConverter::toJson(const StopTransactionReq& data, rapidjs
8386
fill(json, "meterStop", data.meterStop);
8487
fill(json, "timestamp", data.timestamp);
8588
fill(json, "transactionId", data.transactionId);
86-
fill(json, "reason", ReasonHelper.toString(data.reason));
89+
if (data.reason.isSet())
90+
{
91+
fill(json, "reason", ReasonHelper.toString(data.reason));
92+
}
8793
if (!data.transactionData.empty())
8894
{
8995
rapidjson::Value transactionData(rapidjson::kArrayType);

src/messages/StopTransaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct StopTransactionReq
5151
int transactionId;
5252
/** @brief Optional. This contains the reason why the transaction was stopped. MAY only
5353
be omitted when the Reason is "Local". */
54-
ocpp::types::Reason reason;
54+
ocpp::types::Optional<ocpp::types::Reason> reason;
5555
/** @brief Optional. This contains transaction usage details relevant for billing purposes */
5656
std::vector<ocpp::types::MeterValue> transactionData;
5757
};

0 commit comments

Comments
 (0)