Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonException when deserializing projection from FT.SEARCH of JSON value #518

Open
mfaulcon opened this issue Feb 7, 2025 · 1 comment · May be fixed by #519
Open

JsonException when deserializing projection from FT.SEARCH of JSON value #518

mfaulcon opened this issue Feb 7, 2025 · 1 comment · May be fixed by #519

Comments

@mfaulcon
Copy link

mfaulcon commented Feb 7, 2025

While testing performance of a local project using RedisOM and GraphQL, I encountered a difference in the behavior of Redis that leads to a System.Text.Json.JsonException during deserialization. Specifically, when enumerating the RedisCollection without projection, I encountered no issues; an example of the Redis query and response is below:

Query: FT.SEARCH graph3_user_index * LIMIT 0 10 SORTBY UserId ASC
Response (first record):
{
  "UserId": "<obfuscated>",
  "PrincipalName": "<obfuscated>",
  "Email": "[email protected]",
  "EmailType": "signInName",
  "FirstName": "nsqsltsac",
  "LastName": "laste",
  "DisplayName": "nsqsltsac laste",
  "Credentials": "none",
  "Phone": "1234567890",
  "Fax": "1234567890",
  "IsApproved": false,
  "IsExternal": false,
  "CreationType": "LocalAccount",
  "CreatedOn": 1650361275000
}

Running a similar query with a projection from GraphQL against the same Redis Db produced a different result, however, as well as the exception:

Query: FT.SEARCH graph3_user_index * LIMIT 0 11 RETURN 18 UserId AS UserId Email AS Email FirstName AS FirstName LastName AS LastName DisplayName AS DisplayName IsApproved AS IsApproved SORTBY UserId ASC
Response (first record):
[
  "UserId",
  "<obfuscated>",
  "Email",
  "[email protected]",
  "FirstName",
  "nsqsltsac",
  "LastName",
  "laste",
  "DisplayName",
  "nsqsltsac laste",
  "IsApproved",
  "0"
]

Of particular not is that in this case, IsApproved was returned as a number instead of as a string. During deserialization, this resulted in the JsonException, with the inner exception "InvalidOperationException: Cannot get the value of a token type 'Number' as a boolean".

Is this a known issue? I've created a fork of RedisOM and added some code to

ret += $"\"{propertyName}\":{((string)hash[lookupPropertyName]).ToLower()},";
to handle the possibility of both string and numerical representations of a boolean value, but I'm not sure if I should be submitting it.

-                    ret += $"\"{propertyName}\":{((string)hash[lookupPropertyName]).ToLower()},";
+                    var propValue = ((string)hash[lookupPropertyName]).ToLower();
+                    propValue = propValue == "0"
+                        ? "false"
+                        : propValue == "1"
+                            ? "true"
+                            : propValue;
+                    ret += $"\"{propertyName}\":{propValue},";
@slorello89
Copy link
Member

Not a case I've ever run into before, probably do need something in the object handler to handle this particular case. What you have posted above looks roughly correct.

mfaulcon pushed a commit to mfaulcon/redis-om-dotnet that referenced this issue Feb 7, 2025
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 a pull request may close this issue.

2 participants