public JObject ToJSON() => JSONObject.Create( AuthToken.HasValue ? new JProperty("authToken", AuthToken.ToString()) : null, QRCodeIdentification != null ? new JProperty("QRCodeIdentification", QRCodeIdentification.ToString()) : null, PlugAndChargeIdentification.HasValue ? new JProperty("plugAndChargeIdentification", PlugAndChargeIdentification.ToString()) : null, RemoteIdentification.HasValue ? new JProperty("remoteIdentification", RemoteIdentification.ToString()) : null, PIN.HasValue ? new JProperty("PIN", PIN.ToString()) : null, PublicKey != null ? new JProperty("publicKey", PublicKey.ToString()) : null );
/// <summary> /// Try to parse the given JSON representation of an identification. /// </summary> /// <param name="JSON">The JSON to parse.</param> /// <param name="Identification">The parsed identification.</param> /// <param name="ErrorResponse">An optional error response.</param> /// <param name="CustomIdentificationParser">A delegate to parse custom identification JSON objects.</param> public static Boolean TryParse(JObject JSON, out Identification Identification, out String ErrorResponse, CustomJObjectParserDelegate <Identification> CustomIdentificationParser) { try { Identification = default; if (JSON?.HasValues != true) { ErrorResponse = "The given JSON object must not be null or empty!"; return(false); } #region Parse RFIDMifareFamilyIdentification [optional] UID?UID = default; if (JSON.ParseOptional("RFIDMifareFamilyIdentification", "RFID mifare family identification", out JObject RFIDMifareFamilyIdentification, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } if (!RFIDMifareFamilyIdentification.ParseMandatory("UID", "RFID mifare family identification -> UID", OICPv2_3.UID.TryParse, out UID uid, out ErrorResponse)) { return(false); } UID = uid; } #endregion #region Parse RFIDIdentification [optional] if (JSON.ParseOptionalJSON("RFIDIdentification", "RFID identification", OICPv2_3.RFIDIdentification.TryParse, out RFIDIdentification RFIDIdentification, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse QRCodeIdentification [optional] if (JSON.ParseOptionalJSON("QRCodeIdentification", "QR code identification", OICPv2_3.QRCodeIdentification.TryParse, out QRCodeIdentification? QRCodeIdentification, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } } #endregion #region Parse PlugAndChargeIdentification [optional] EVCO_Id?PnC_EVCOId = default; if (JSON.ParseOptional("PlugAndChargeIdentification", "plug & charge identification", out JObject plugAndChargeIdentification, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } if (!plugAndChargeIdentification.ParseMandatory("EvcoID", "plug & charge identification -> EVCOId", EVCO_Id.TryParse, out EVCO_Id evcoId, out ErrorResponse)) { return(false); } PnC_EVCOId = evcoId; } #endregion #region Parse RemoteIdentification [optional] EVCO_Id?Remote_EVCOId = default; if (JSON.ParseOptional("RemoteIdentification", "remote identification", out JObject RemoteIdentification, out ErrorResponse)) { if (ErrorResponse != null) { return(false); } if (!RemoteIdentification.ParseMandatory("EvcoID", "remote identification -> EVCOId", EVCO_Id.TryParse, out EVCO_Id evcoId, out ErrorResponse)) { return(false); } Remote_EVCOId = evcoId; } #endregion Identification = new Identification(UID, RFIDIdentification, QRCodeIdentification, PnC_EVCOId, Remote_EVCOId); if (CustomIdentificationParser != null) { Identification = CustomIdentificationParser(JSON, Identification); } return(true); } catch (Exception e) { Identification = default; ErrorResponse = "The given JSON representation of an identification is invalid: " + e.Message; return(false); } }