I have a request body that uses an inherited class, but the properties of that class are not being serialized when sent to Jira.
Below is my model, you can see that BuildUpdateFields is inheriting from JiraFields
public record JiraFields
{
public string Summary { get; set; }
[JsonPropertyName("issuetype")]
public IssueType IssueType { get; set; }
public Project Project { get; set; }
}
public record BuildUpdateFields : JiraFields
{
[JsonPropertyName("customfield_10272")]
public string? ProjectId { get; set; }
// validation date (YYYY-MM-DD)
[JsonPropertyName("customfield_10219")]
public string? ValidationDate { get; set; }
}
And below is the implementation:
public async Task<string> CreateBuildUpdateTicket(
BuildUpdateTicketRequest buildUpdateTicketRequest,
CancellationToken cancel
)
{
var jiraCreateIssueRequest = new JiraCreateIssueRequest
{
Fields = new BuildUpdateFields
{
Summary = buildUpdateTicketRequest.IssueSummary,
IssueType = new IssueType { Id = "10115" },
Project = new Project { Id = "10023" },
ProjectId = buildUpdateTicketRequest.ProjectId,
ValidationDate = buildUpdateTicketRequest.ValidationDate,
}
};
var systemTextJson = JsonSerializer.Serialize<object>(jiraCreateIssueRequest);
var newtownSoftJson = JsonConvert.SerializeObject(jiraCreateIssueRequest);
try
{
JiraCreateIssueResponse jiraCreateIssueResponse = await _jiraCloudClient.CreateIssue(
newtownSoftJson
);
return jiraCreateIssueResponse.Id;
}
catch (Refit.ApiException apiException)
{
Log.Error("API request failed with status code: " + apiException.StatusCode);
if (apiException.Content != null)
{
Log.Error("API response content: " + apiException.Content);
}
throw;
}
}
You can see I've tried two different serializers. The Newtonsoft one actually does serialize ProjectId and ValidationDate:
{"Fields":{"Summary":"Anaheim, CA","issuetype":{"Id":"10115"},"Project":{"Id":"10023"}}}
{"Fields":{"ProjectId":"1234","ValidationDate":"2023-10-05","Summary":"Anaheim, CA","IssueType":{"Id":"10115"},"Project":{"Id":"10023"}}}
However, then sending newtownSoftJson off to Jira with string type returns
["No content to map to Object due to end of input"]
I've been trying every iteration I can think of with this. If anybody has any suggestions, I would really appreciate it.
Hi @Colin -- Welcome to the Atlassian Community!
You may want to also post your question in the developer community: https://community.developer.atlassian.com/
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.