How do I add FunctionMappers to ExpressionManager in 7.18

I see that ExpressionManager has changed in 7.18,
Adjusted class structure for Expression Language handling, and that it no longer has an addFunctionMapper() operation.

Prior to 7.18 we were registering FunctionManagers by doing the following:

processEngineConfiguration.getExpressionManager().addFunctionMapper(new MyFunctionMapper()); 

What would be the new approach?

Thank you,
Burt Repine

Hi @brepine ,

now you can only add functions via the ExpressionManager interface. If you want to keep using your custom function mappers, you could subclass the existing ExpressionManager, e. g. write a subclass of the JuelExpressionManager which only overwrites the createFunctionMapperFunction which then enables you to respect additional function mappers.

I could think of something like the following. Warning: I have not tested this code.

public class CustomJuelExpressionManager extends JuelExpressionManager {

    private Collection<FunctionMapper> additionalFunctionMappers = new LinkedList<>();

    public void addFunctionMapper(FunctionMapper functionMapper) {
        additionalFunctionMappers.add(functionMapper);
    }

    @Override
    protected FunctionMapper createFunctionMapper() {
        FunctionMapper baseMapper = super.createFunctionMapper();
        return new FunctionMapper() {
            @Override
            public Method resolveFunction(String prefix, String localName) {
                return Optional.ofNullable(baseMapper.resolveFunction(prefix, localName))
                        .or(() -> additionalFunctionMappers.stream().flatMap(mapper -> Optional.ofNullable(mapper.resolveFunction(prefix, localName)).stream()).findFirst())
                        .orElse(null);
            }
        };
    }
}

Otherwise, you would need to rewrite your function mappers and register every function itself which might be easier for you.

I hope this helps,
Adagatiya

1 Like

Worked for me, thank you Adagatiya

1 Like