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

DateTime filters return nil results when using JsonObject as a source #698

Open
StephenMLucas opened this issue Sep 4, 2024 · 0 comments

Comments

@StephenMLucas
Copy link

When using a System.Text.Json JsonObject as the TemplateContext then it is not possible to directly use filters like time_zone or date on string properties in the source json as the result is always nil.

Stepping through in the debugger it can be seen that in this case the individual JsonElements for the properties are being wrapped in a FluidValue of type FluidValues.Object. However FluidValueExtensions.TryGetDateTimeInput does not handle this case and returns false.

As a workaround it is possible to call another string filter first, e.g. strip, which internally calls FluidValue.ToStringValue() which unwraps the JsonElement string value and provides it as a FluidValues.String to subsequent filters which then succeed.

I believe the straightforward fix to this issue would be either to extend FluidValueExtensions.TryGetDateTimeInput to add a call to FluidValue.ToStringValue() on the fallback paths before returning false, or to explicitly handle the JsonElement case in the same object type switch statement used for DateTime & DateTimeOffset objects if JsonElement is also considered a Well Known Type for Fluid.

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

No branches or pull requests

1 participant