@@ -47,9 +47,12 @@ bool ClearChargingProfileReqConverter::fromJson(const rapidjson::Value& json,
4747 std::string& error_message)
4848{
4949 extract (json, " id" , data.id );
50- bool ret = extract (json, " connectorId" , data.connectorId , error_message);
51- data.chargingProfilePurpose = ChargingProfilePurposeTypeHelper.fromString (json[" chargingProfilePurpose" ].GetString ());
52- ret = ret && extract (json, " stackLevel" , data.stackLevel , error_message);
50+ bool ret = extract (json, " connectorId" , data.connectorId , error_message);
51+ if (json.HasMember (" chargingProfilePurpose" ))
52+ {
53+ data.chargingProfilePurpose = ChargingProfilePurposeTypeHelper.fromString (json[" chargingProfilePurpose" ].GetString ());
54+ }
55+ ret = ret && extract (json, " stackLevel" , data.stackLevel , error_message);
5356 if (!ret)
5457 {
5558 error_code = ocpp::rpc::IRpc::RPC_ERROR_TYPE_CONSTRAINT_VIOLATION;
@@ -62,7 +65,10 @@ bool ClearChargingProfileReqConverter::toJson(const ClearChargingProfileReq& dat
6265{
6366 fill (json, " id" , data.id );
6467 fill (json, " connectorId" , data.connectorId );
65- fill (json, " chargingProfilePurpose" , ChargingProfilePurposeTypeHelper.toString (data.chargingProfilePurpose ));
68+ if (data.chargingProfilePurpose .isSet ())
69+ {
70+ fill (json, " chargingProfilePurpose" , ChargingProfilePurposeTypeHelper.toString (data.chargingProfilePurpose ));
71+ }
6672 fill (json, " stackLevel" , data.stackLevel );
6773 return true ;
6874}
0 commit comments