Skip to content

Add support for DateOnly/TimeOnly into xml serializer#7692

Merged
danielmarbach merged 7 commits intomasterfrom
xml-date-time-only
Apr 15, 2026
Merged

Add support for DateOnly/TimeOnly into xml serializer#7692
danielmarbach merged 7 commits intomasterfrom
xml-date-time-only

Conversation

@rbev
Copy link
Copy Markdown
Contributor

@rbev rbev commented Apr 9, 2026

Fix for #7126

@rbev rbev requested review from andreasohlund and tmasternak April 9, 2026 09:23
@andreasohlund andreasohlund added this to the 10.2.0 milestone Apr 9, 2026
@andreasohlund andreasohlund added the Small Task Item that is put on the Small Tasks board label Apr 9, 2026
@andreasohlund andreasohlund added Improvement and removed Small Task Item that is put on the Small Tasks board labels Apr 9, 2026
Comment thread src/NServiceBus.Core/Serializers/XML/XmlDeserialization.cs Outdated
Copy link
Copy Markdown
Member

@tmasternak tmasternak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards the approach indicated by Daniel - explicit type handling

Comment thread src/NServiceBus.Core/Serializers/XML/XmlSerialization.cs Outdated
Comment thread src/NServiceBus.Core/Serializers/XML/XmlSerialization.cs
Comment thread src/NServiceBus.Core.Tests/Serializers/XML/SerializerTests.cs Outdated
@danielmarbach
Copy link
Copy Markdown
Contributor

I dug a little deeper because I was wondering how DateTime and DateTimeOffset are handled internally. I found out that XElement has native support for that and started wonder why we even have to do anything. This made me find this gem dotnet/runtime#119835

@danielmarbach
Copy link
Copy Markdown
Contributor

Raised dotnet/runtime#126879.

@danielmarbach
Copy link
Copy Markdown
Contributor

Looking at the .NET runtime PR, the wire formats are:

  • DateOnly → yyyy-MM-dd
  • TimeOnly → HH:mm:ss[.FFFFFFF] (trimmed trailing zeros, not full roundtrip format)

Our current "O" format for TimeOnly produces 14:30:25.1230000 with trailing zeros, while the runtime uses a minimal form like 14:30:25.123.

Should we use yyyy-MM-dd and HH:mm:ss.fffffff (trimmed) instead of "O" to match the .NET runtime behavior? Or is our current "O" format acceptable since it's also a valid roundtrip format?

@rbev
Copy link
Copy Markdown
Contributor Author

rbev commented Apr 15, 2026

I dug a little deeper because I was wondering how DateTime and DateTimeOffset are handled internally. I found out that XElement has native support for that and started wonder why we even have to do anything. This made me find this gem dotnet/runtime#119835

Yeah i saw that one too and was surprised that XElement was still using the plain .ToString() when they had added support to the other XML serialisers.

@rbev
Copy link
Copy Markdown
Contributor Author

rbev commented Apr 15, 2026

Should we use yyyy-MM-dd and HH:mm:ss.fffffff (trimmed) instead of "O" to match the .NET runtime behavior? Or is our current "O" format acceptable since it's also a valid roundtrip format?

I think "O" would be acceptable - It's not going to break anyone, but I think the trimmed version would be slightly better as it will generally drop 3 or more bytes from each message.

@danielmarbach danielmarbach merged commit 7b9b07b into master Apr 15, 2026
4 checks passed
@danielmarbach danielmarbach deleted the xml-date-time-only branch April 15, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants