0

I made a dotnet core console app that serializes a custom object using Newtonsoft.Json v12.0.3.

I want to be able to serialize my custom objects DateTime property without quotes.

I'm trying to avoid making a custom JsonConverter or changing the datatype to be an int or other number types. I'm using DateFormatConverter from here: https://stackoverflow.com/a/44893493/1440321

[JsonConverter(typeof(DateFormatConverter), "yyyyMMdd")]
[JsonProperty("fileGenerationDate", Order = 3)]
public DateTime FileGenerationDate { get; set; }

Desired Output:

{
    ...
    "fileGenerationDate": 20180919
}

Current Output:

{
    ...
    "fileGenerationDate": "20180919"
}
Paul Totzke
  • 1,470
  • 17
  • 33

1 Answers1

1

You'll have to create your own JsonConverter because the one that comes out-of-the-box writes values as string and strings are always serialized with quotes...

You can copy the code of IsoDateTimeConverter and change it to write the value as an int.

C. Augusto Proiete
  • 24,684
  • 2
  • 63
  • 91