Skip to content

Commit

Permalink
Count Optional as resolvable inside EagerExpressionResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmith-hs committed May 15, 2024
1 parent f3ab01a commit 363cae2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -335,6 +336,11 @@ private static boolean isResolvableObjectRec(
}
return (Arrays.stream((Object[]) val)).filter(Objects::nonNull)
.allMatch(item -> isResolvableObjectRec(item, depth + 1, maxDepth, maxSize));
} else if (val instanceof Optional) {
return ((Optional<?>) val).map(item ->
isResolvableObjectRec(item, depth + 1, maxDepth, maxSize)
)
.orElse(true);
}
} catch (DeferredValueException e) {
if (!(val instanceof PartiallyDeferredValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,4 +954,14 @@ public void itCountsBigDecimalAsPrimitive() {
assertThat(EagerExpressionResolver.isResolvableObject(new BigDecimal("2.1E7")))
.isTrue();
}

@Test
public void itCountsOptionalAsResolvable() {
assertThat(
EagerExpressionResolver.isResolvableObject(
ImmutableList.of(Optional.of(123), Optional.empty())
)
)
.isTrue();
}
}

0 comments on commit 363cae2

Please sign in to comment.