Depending on the licence I query, I get two different JSON responses. On Success I get the "success" string and on error I get the "code" string. Now, I have built a two constructors class to catch both cases.
When I deserialize the json string with:
License license = JsonConvert.DeserializeObject<License>(json_str);
I get the error: "Unable to find a constructor to use for type..."
Here is the code, any suggestions:
//JSON String on Success -> {"success":true,"data":{"id":54,"orderId":109,"productId":79,"userId":1,"licenseKey":"1y10a3P-YL-A1-EQ-F9-GI-DM-W3","expiresAt":"2022-09-04 09:02:40","validFor":365,"source":1,"status":2,"timesActivated":null,"timesActivatedMax":1,"createdAt":"2021-09-04 09:02:40","createdBy":0,"updatedAt":"2021-09-04 09:02:40","updatedBy":0}}
//JSON String on error -> {"code":"lmfwc_rest_license_expired","message":"The license Key expired on 2021-10-06 00:00:00 (UTC).","data":{"status":405}}
public partial class License
{
[JsonProperty("success")]
public bool Success { get; set; }
[JsonProperty("data")]
public Success_Data Success_Data { get; set; }
[JsonProperty("code")]
public String Code { get; set; }
[JsonProperty("message")]
public String Message { get; set; }
[JsonProperty(PropertyName = "error_data")]
public Error_Data Error_Data { get; set; }
public License(bool success, Success_Data data)
{
Success = success;
Success_Data = data;
}
public License(String code, String message, Error_Data error_data)
{
Code = code;
Message = message;
Error_Data = error_data;
}
}
public partial class Error_Data
{
[JsonProperty("status")]
public long Status { get; set; }
}
public partial class Success_Data
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("orderId")]
public long OrderId { get; set; }
[JsonProperty("productId")]
public long ProductId { get; set; }
[JsonProperty("userId")]
public long UserId { get; set; }
[JsonProperty("licenseKey")]
public string LicenseKey { get; set; }
[JsonProperty("expiresAt")]
public DateTimeOffset ExpiresAt { get; set; }
[JsonProperty("validFor")]
public object ValidFor { get; set; }
... }