Skip to content

Fix JsonPolymorphic attribute with DisableDotvvmConverter=true#2007

Open
exyi wants to merge 1 commit intomainfrom
fix-JsonPolymorphic-with-optout
Open

Fix JsonPolymorphic attribute with DisableDotvvmConverter=true#2007
exyi wants to merge 1 commit intomainfrom
fix-JsonPolymorphic-with-optout

Conversation

@exyi
Copy link
Member

@exyi exyi commented Feb 27, 2026

Main fix is that we need to use type: dynamic in metadata, because System.Text.Json does not tolerate any properties starting with $ during deserialization.

Apart from that I added error during initialization if you use JsonPolymorphic and did not set DisableDotvvmConverter, since it's most likely unintended.
We also want to add support for this later, and if make it a hard error now, it won't be a breaking change to add some support.

Main fix is that we need to use `type: dynamic` in metadata, because
System.Text.Json does not tolerate any properties starting with `$`
during deserialization.

Apart from that I added error during initialization if you use
JsonPolymorphic and did not set DisableDotvvmConverter,
since it's most likely unintended.
We also want to add support for this later, and if make it a hard error
now, it won't be a breaking change to add some support.
Comment on lines +231 to +237
if (!disableDotvvmConverter)
{
if (type.IsDefined(typeof(JsonPolymorphicAttribute)))
throw new NotSupportedException(
$"Can not serialize {type.ToCode()} as [JsonPolymorphic] attribute is currently not supported by DotVVM. " +
"You can use [DotvvmSerialization(DisableDotvvmConverter = true)] to fall back to System.Text.Json default behavior, please note the client-side bindings to such models may not work properly.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant