-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change scope constructor from private to protected #221
Comments
You are right, currently, variable values must be pre-computed and there's no way to do dynamic or lazy evaluation. The closest you can do is to implement a custom function instead of using a variable: scope.addFunction("foo", 0, new Function() {
@Override
public void apply(Scope scope, List<Expression> args, JsonNode in, Path path, PathOutput output, Version version) throws JsonQueryException {
JsonNode value = ... // obtain the value here
output.emit(value, null);
}
}); I'm willing to support dynamic/lazy variables, but rather than allowing subclassing the scope class, I want to add a new setValue overload that takes a ValueSource instance: interface ValueSource {
JsonNode getValue();
}
public class Scope {
public void setValue(String name, JsonNode value) { ... };
public void setValue(String name, ValueSource valueSource) { ... }; // the new overload
}
// This can be used like this:
// scope.setValue("foo", () -> new TextNode("this value is lazily evaluated")); What do you think? Does this work for you? |
@eiiches Thanks for the response. |
@eiiches Should I open a PR implementing what we discussed? I think the method to be added should be
So you can write The point is that you do not know if your external source can resolve a particular key at the moment you are configuring the scope |
It will be great if scope class can be extended (although the class is not final, the construtor is private)
For example, to dynamically retrieve variable values from an extenal source by overriding getValue method.
AFAIK, the only way to change the behaviour of getValue is by invoking setValue, but there might be cases where your variable source (for example a DB) has a dynamic nature.
The text was updated successfully, but these errors were encountered: