Skip to content

Allow mapping CLR types to JSON at the type mapper level #2568

@roji

Description

@roji

Our current JSON support - both the older JSON.NET plugin and the newer System.Text.Json support introduced in #2306 - require you to manually specify NpgsqlDbType.{Json,Jsonb} on every parameter. In other words, it is currently not possible to map a user POCO type to json/jsonb at the global or connector level (the JSON.NET plugin exposes an API for this, but it does not actually work for over a single type).

This is because our type mapping currently doesn't support a situation where more than one CLR type is mapped to the same PostgreSQL type.

Note: it will not be possible to have the user POCO returned by default when reading (i.e. without explicitly specifying it in GetFieldValue), since there's no way for us to distinguish between incoming JSON documents coming back from the database.

Another reason we need to allow mapping at the type mapper level, is in order to allow the user to specify JSON serialization options.

This is very related (and could be a dup of) #2439.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions