Supporting JSON serialized columns

31 views
Skip to first unread message

Michael W Powell

unread,
Jun 1, 2025, 1:22:39 PMJun 1
to nhusers
I'm looking for a halfway decent IUserType implementation in support of JSON serialized columns. Many of the examples I am finding seem to assume that a default JSON representation should be an object i.e. "{}". However, I do have a couple of instances in which I actually want an array, i.e. "[]". That's number one.

Number two, are there other methods or extensions methods of the Map(...) that allow further customization of such an implementation than just a default constructor (presumably), i.e.

Map(x => x.Features)
    .CustomType<JsonColumnType<IList<string>>>()
    .Column((nameof(ServerProfile.Features) + "Json").ToCamelCase())
    .Not.Nullable()
    ;

And then, if I would like to do a measure of custom JSON serialization to from the source property, then what. Other than of course a nominal default implementation.

I might like to do something like this for instance, but I do not see that extension:

Map(x => x.Features)
    .CustomType<JsonColumnType<IList<string>>>(() => /* do something to initialize and configure */ )
    ;

Thank you, best,

Michael W. Powell

Michael W Powell

unread,
Jun 2, 2025, 3:04:47 PMJun 2
to nhusers
Interestingly enough I ended up going to one of those chat agents to crank out some boilerplate, which I reviewed, and mostly liked the result, with a couple of adjustments on my part. I think I have it somewhat sorted now. We'll see how it works. The only other thing I might consider is whether the pg JSON dialect needs stronger support than just an open String(2K) or what have you. Like I think those types can potentially be better mapped via Npgsql terms IIRC. Will have to see.
Reply all
Reply to author
Forward
0 new messages