internal static ErrorResponse DeserializeErrorResponse(JsonElement element) { Optional <string> code = default; Optional <string> message = default; Optional <string> target = default; Optional <IReadOnlyList <ErrorResponse> > details = default; Optional <IReadOnlyList <ErrorAdditionalInfo> > additionalInfo = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code")) { code = property.Value.GetString(); continue; } if (property.NameEquals("message")) { message = property.Value.GetString(); continue; } if (property.NameEquals("target")) { target = property.Value.GetString(); continue; } if (property.NameEquals("details")) { List <ErrorResponse> array = new List <ErrorResponse>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(DeserializeErrorResponse(item)); } details = array; continue; } if (property.NameEquals("additionalInfo")) { List <ErrorAdditionalInfo> array = new List <ErrorAdditionalInfo>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(ErrorAdditionalInfo.DeserializeErrorAdditionalInfo(item)); } additionalInfo = array; continue; } } return(new ErrorResponse(code.Value, message.Value, target.Value, Optional.ToList(details), Optional.ToList(additionalInfo))); }
internal static ErrorResponse DeserializeErrorResponse(JsonElement element) { string code = default; string message = default; string target = default; IReadOnlyList <ErrorResponse> details = default; IReadOnlyList <ErrorAdditionalInfo> additionalInfo = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } code = property.Value.GetString(); continue; } if (property.NameEquals("message")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } message = property.Value.GetString(); continue; } if (property.NameEquals("target")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } target = property.Value.GetString(); continue; } if (property.NameEquals("details")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <ErrorResponse> array = new List <ErrorResponse>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(DeserializeErrorResponse(item)); } } details = array; continue; } if (property.NameEquals("additionalInfo")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } List <ErrorAdditionalInfo> array = new List <ErrorAdditionalInfo>(); foreach (var item in property.Value.EnumerateArray()) { if (item.ValueKind == JsonValueKind.Null) { array.Add(null); } else { array.Add(ErrorAdditionalInfo.DeserializeErrorAdditionalInfo(item)); } } additionalInfo = array; continue; } } return(new ErrorResponse(code, message, target, details, additionalInfo)); }