Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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!
Oct 06, 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.
Oct 06, 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