Skip to content

Commit

Permalink
Merge pull request #1186 from HubSpot/optional-resolvable
Browse files Browse the repository at this point in the history
Count Optional as resolvable inside EagerExpressionResolver
  • Loading branch information
jasmith-hs authored May 16, 2024
2 parents ee49945 + 363cae2 commit b5e4e74
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 b5e4e74

Please sign in to comment.