Skip to content

Commit a1b540e

Browse files
committed
Adding support for the infer of Json data in constants for Web models
1 parent 750f9a9 commit a1b540e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/Deveel.Filter.Model.Web/Filters/FilterModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,12 @@ public virtual IFilter BuildFilter() {
146146
throw new FilterException("The model is invalid - no type was set");
147147

148148
switch (filterType) {
149-
case FilterType.Constant:
150-
return new ConstantFilter(value);
149+
case FilterType.Constant: {
150+
if (value is JsonElement json)
151+
value = JsonElementUtil.InferValue(json);
152+
153+
return new ConstantFilter(value);
154+
}
151155
case FilterType.Not:
152156
if (not == null)
153157
throw new FilterException("The model is invalid - no unary filter was set");
File renamed without changes.

test/Deveel.Filter.Model.Web.XUnit/Filters/FilterBuildTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public static void BuildConstant() {
105105
Assert.Equal(42, constant.Value);
106106
}
107107

108+
[Fact]
109+
public static void BuildConstantWithJson() {
110+
var filter = new FilterModel {
111+
Value = JsonDocument.Parse("42").RootElement
112+
};
113+
114+
var result = filter.BuildFilter();
115+
Assert.NotNull(result);
116+
Assert.IsType<ConstantFilter>(result);
117+
Assert.Equal(FilterType.Constant, result.FilterType);
118+
var constant = (ConstantFilter) result;
119+
Assert.Equal(42, constant.Value);
120+
}
121+
108122
[Fact]
109123
public static void BuildFunction() {
110124
var function = new FilterModel {

0 commit comments

Comments
 (0)