Trouble serializing request body in .NET

Colin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 6, 2023

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.

1 answer

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2023

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events