Projections don't work when changing JSON Settings #2205
Replies: 5 comments 5 replies
-
"
Number 1 isn't feasible. Number 2 is already the behavior, so I'm not sure what you want to happen here. The default casing means that the Json is assumed to exactly match the property or field name. If you're changing how the JSON is serialized, yeah, you're gonna break things and I don't know there's anything we can do about that. You can use the patching to migrate the data. I'm converting this to a discussion for now. |
Beta Was this translation helpful? Give feedback.
-
The postgresql operators are case sensitive though. We have to know how to translate a field/property name to the path within the JSON. |
Beta Was this translation helpful? Give feedback.
-
This isn’t about changing the serialization after the database is created. The issue occurs on a clean database that’s just created. I.e in the test. |
Beta Was this translation helpful? Give feedback.
-
I'm at my desk now so I can write a proper summary. So to be 100% clear: The issue is solely in the configuration of When using the setting:
This will ensure when serialization occurs.
This also means that deserialization looks for So on a new clean database when the setting is set to camelCase everything works correctly in regards to CRUD operations. The issue only occurs in projection, the reason is: When a projection is run it generates a selection using the SQL Operators to build a new JSON document.
(1st When it takes the So the way I see it is we have 2 options. Option 1 (more risky, but... more correct?)We change the generation of the SQL. Because we use the configured casing to decide that the Document POCO changes This would mean no changes are required for the System.Text.Json configuration, but obviously affect everything else. This feels more correct as the alignment of the SQL generation matches the configuration used for persistence and querying. But we are less likely to know if this has any other bugs pop out we aren't aware of. Option 2We change the serializer.
https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-character-casing
This setting only affects the deserialization from JSON to POCO. Thus we should be able to just enable it by default and be done with it. This wont have any affect on the serialization for persistance or the casing of the properties for persistance. It just means that it doesn't case what the casing in the JSON document is, it will match the property of the POCO you're trying to rehydrate. Personaly I think it's really stupid that this is not the default setting. But enforcing case sensitivity probably shaved off 0.01ns from the performance so they could claim its crazy fast. While I'm 100% sure this is absolutely perfectly safe to enable. I'm unsure if it's worth the risk. That's why my PR put it behind a property. |
Beta Was this translation helpful? Give feedback.
-
@jeremydmiller have you had any more thoughts on this? I’ve been thinking and think we either do:
Or
|
Beta Was this translation helpful? Give feedback.
-
I have not verified this using Newtonsoft.Json but it's a bug that affects System.Text.Json.
Given the following:
If you have a document such as:
And you want to project this to say:
Querying like:
This works... HOWEVER, if you (wipe the database, and start fresh) change the configuration:
Everything works perfectly until you get to the project.
It issues a query like so:
This results in a collection of empty objects.
Name
isnull
andLevel
is0
.I believe this is due to
PropertyNameCaseInsensitive
not being set totrue
in the serializer.So there's 2 ways we can fix this I believe...
Change the serializer to be case insensitive. (This is my preferred approach)
Change the querying to use the same casing as the properties of the JSON. i.e
jsonb_build_object('name', d.data ->> 'name')
Name
->name
since the data property isname
.Beta Was this translation helpful? Give feedback.
All reactions