Rimal opened SPR-17225 and commented
Can we please add a suffix support for BigInteger as well in SpEL.
Currently, we can add a long value as 12345456L (with the L suffix) but for a BigInteger, we need to mention it as new java.math.BigInteger('9248040402')
.
It would be really helpful if we could mention a BigInteger as 9248040402BI or something on these lines.
No further details from SPR-17225
Comment From: ovmarkushyn
@spring-projects-issues Could you please consider PR#31301 as a possible solution for the request #21758.
Comment From: sbrannen
Team Decision:
We consider the proposal to be a bit of a niche feature which does not warrant the complexity it would introduce within the Spring Expression Language (see PR #31301).
In general, at this point in time we do not intend to introduce new language-level features in the Spring Expression Language.
In light of that, we are closing this issue.
In any case, thank you for the proposal!
Comment From: sbrannen
Please note that it's always possible to register your own custom functions for such purposes, as long as you are in control of the setup of the EvaluationContext
.
For example, the following test demonstrates how to register a custom bigInt
function and use it within expressions instead of new java.math.BigInteger('9248040402')
.
@Test
void bigIntegerFunction() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Method method = BigInteger.class.getMethod("valueOf", long.class);
context.registerFunction("bigInt", method);
Expression expression = parser.parseExpression("3 + #bigInt(5)");
BigInteger result = expression.getValue(context, BigInteger.class);
assertThat(result).isEqualTo(BigInteger.valueOf(8));
}
And you could register a similar function (for example, bigDecimal
) for BigDecimal
support.
Hope you find this useful!