Skip to content

Support JSON parsing object to DateTimeOffset and preserve timezone offset in JsonObjectConverter#16732

Merged
bergmania merged 1 commit intov14/devfrom
v14/bugfix/jsonobjectconverter-datetimeoffset
Jul 4, 2024
Merged

Support JSON parsing object to DateTimeOffset and preserve timezone offset in JsonObjectConverter#16732
bergmania merged 1 commit intov14/devfrom
v14/bugfix/jsonobjectconverter-datetimeoffset

Conversation

@ronaldbarendse
Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #16587.

Description

Although I initially thought the CMS data type configuration migration (executed when upgrading v13 to v14) caused Deploy to write updated UDA files, it is actually due to the JsonObjectConverter (that's used by the IConfigurationEditorJsonSerializer for reading and writing data type configuration) not correctly parsing DataTimeOffset values.

This custom JsonConverter takes care of deserializing JSON values into object instances to their simple/primitive types (boolean, integer, date or string), instead of a boxed JsonElement (see https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-9-0#deserialization-of-object-properties). I assume this has been copied from the example in the Microsoft documentation, which clearly isn't really suitable to be used in production 🫤 Removing this converter would be a massive breaking change, as values will be parsed differently when deserializing, but I would suggest looking into thing for a future major release, as this also contains multiple performance issues (loading everything into lists, casting, creating generic types and new instances via reflection, etc.)...

@ronaldbarendse ronaldbarendse requested review from bergmania and kjac July 3, 2024 20:36
@bergmania
Copy link
Copy Markdown
Member

Thanks for the PR.. Sadly this is super required by the block editors currently.

@bergmania bergmania merged commit 4643b7d into v14/dev Jul 4, 2024
@bergmania bergmania deleted the v14/bugfix/jsonobjectconverter-datetimeoffset branch July 4, 2024 05:36
bergmania pushed a commit that referenced this pull request Jul 4, 2024
@bergmania
Copy link
Copy Markdown
Member

Cherry picked to 14.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants