0

I need to create a data class which used for JsonConvert. Most of the resource string which used to be converted are same except the following properties:

public class DataType
{
        public DateTimeOffset CreateDate { get; set; }
        public DateTimeOffset Create_Date { get; set; }
}

Because in the resource string there are 2 types : "create_date": "2021-01-15T18:43:13.061+0000", & "createdate": "2021-01-15T18:43:13.061+0000",

with the following JsonConvert:

JsonConvert.DeserializeObject<DataType>(resourceStr);

The output of one of the datetime property will be wrong value. Is there a good way to use one property to handle both of these two formats?

dbc
  • 104,963
  • 20
  • 228
  • 340
Deritha
  • 67
  • 2
  • 9
  • 1
    Please [edit] the question with [MCVE] including inline JSON value as constant in the code. Very unclear what exactly does not work and what you expect to happen. – Alexei Levenkov Jan 27 '21 at 01:25

1 Answers1

0

It's resolved by add another private property with alter name. Then the class will support to convert both CreateDate and Create_Date with a single display name;

public DateTimeOffset CreateDate { get; set; }

[JsonProperty("Create_Date")]
        private DateTimeOffset CreateDate2
        {
            set => CreateDate = value;
        }
Deritha
  • 67
  • 2
  • 9