Skip to content

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

@StephenMLucas

Description

@StephenMLucas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions