Skip to content

JSON polymorphism: allow reading different JSON documents based on e.g. a discriminator property #4862

@roji

Description

@roji

It's fairly common to have different document types in the same PG JSON column (after all, JSON is weakly-typed). Npgsql already allows giving a list of types which are mapped to jsonb, so that they can be written without specifying NpgsqlDbType.Jsonb. It seems useful to allow a similar thing for the read side: the user would configure the System.Text.Json plugin with a function which accepts a JsonDocument and returns a Type, and Npgsql would automatically execute that function and deserialize to that type. Typically a JSON property would act as the discriminator, but other schemes can be imagined as well.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions