System.Text.Json UTC DateTime Issue in C#

Timothy Fischer 121 Reputation points

I'm trying to deserialize a Json response into a class that looks like this:

jiraResponseMessage = JsonSerializer.Deserialize<InternalJiraIssuesResponse>(responseString);

When running the code, I keep getting the following error:

The JSON value could not be converted to System.DateTime. Path: $.issues[0].changelog.histories[0].created | LineNumber: 0 | BytePositionInLine: 1451.

The error is being thrown when trying to deserialize this part :


Can anyone help me to figure out how to get the Json to be deserialized for this?

This is the class I have for deserializing:

public class History
    public string id { get; set; }
    public Author author { get; set; }
    public DateTime created { get; set; }
    public Item[] items { get; set; }

Even when changing "created" to a string or object, it still chokes.

Any ideas on how I can resolve this?

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,501 questions
0 comments No comments
{count} votes

Accepted answer
  1. Timothy Fischer 121 Reputation points

    Weird...all of a sudden it works when I change to string:
    -- public string created { get; set; }

    I swear it was throwing the exception I posted earlier, even after I changed it from DateTime to a string

    Thanks for your help Paul! You rock!

2 additional answers

Sort by: Most helpful
  1. P a u l 10,406 Reputation points

    ISO 8601 date formats have a colon between the hours & minutes of the timezone offset like this:

    Did you hand write this or was this serialised programmatically?

    Edit: Actually it looks like this format just isn't supported.

    According to this comment the offset that contains the colon is the extended format that the JsonSerializer supports only be default.

    He did reference this article which explains how to make a DateTime/DateTimeOffset converter to handle this case though:

    0 comments No comments

  2. Timothy Fischer 121 Reputation points

    Is there a way I could trick the deserializer into thinking it is a string instead -- I did read the articles in the links you added prior to asking the question...mainly because I'm trying to pull into a class and I did not see any samples there :(

    I would think that because the datetime comes over in string format (i.e. "created": "##:##T##...") that I could just pull it in my class as a string rather than datetime.

    Thanks for the response.