Derek
Derek

Reputation: 8773

NodaTime - can I change default xml serialization for Instant?

NodaTime - can I change default xml serialization for Instant?

Is there a way to change it so all instants would be serialized without milliseconds:

Instead of this:

<CreationDateTime>2021-06-27T09:52:18.1900643Z</CreationDateTime>

I'd want this:

<CreationDateTime>2021-06-27T09:52:18Z</CreationDateTime> 

I'm wondering if there is a way to do that for all NodaTime.Instant properties, e.g. with some settings on the XmlSerializer we create?

Upvotes: 0

Views: 110

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1502166

No, I'm afraid not: the format is hard-coded, effectively. I would suggest either post-processing the XML, or potentially serializing using a separate string property which is purely for the sake of XML (so you'd mark it as obsolete, but serialize it in the way that you want, and it would proxy to an Instant property which is not obsolete but is ignored for XML serialization).

Upvotes: 1

Related Questions