I have defined a ProblemDetails
class. I construct an object of this class and return from my Http triggered Azure function upon error.
I have defined a convenience property HasDetail
to tell if the object has any detail meaning if the object is empty. However, i don't want this property to be included in the response body. I have applied the [JsonIgnore]
attribute as well hoping it will not expose that particular property but i still see this property in the response body. How do i stop this?
Note:
The code and the response are below
I am using system.text.json
Class:
public class ProblemDetails
{
public string Type { get; set; }
public string Title { get; set; }
public int? Status { get; set; }
public string Detail { get; set; }
public string Instance { get; set; }
[JsonIgnore]
public bool HasDetail {
get
{
return !result;
}
}
}
Response body as JSON:
{
"type": "https://aaa/codes",
"title": "Input Not Provided",
"status": 400,
"detail": "Please provide a group name or groupId.",
"instance": "",
"hasDetail": true
}
Azure Function declaration
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK,
contentType: "application/json",
bodyType: typeof(bool),
Description = "The OK response.")]
[FunctionName(FunctionNames.SomeName)]
public async Task<IActionResult> SomeName(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req)
{
// do something
}