Hi,
first of all thanks for the great recent upgrades to the date handling and other improvements!
I am now dealing with specific scenario, where we are using expression for data transformation from incoming JSONs through endpoints. The issue is following:
Imagine we have following JSON:
[{
"productId": "p-1",
"name": "Laptop",
"quantity": 1,
"price": 1200.50,
"discount": null,
"non_existing" : "test"
},
{
"productId": "p-2",
"name": "Mouse",
"quantity": 2,
"price": 25.00,
"discount": 5.00
} ]
For each record we provide the JSON as custom context, but in the second record the "non_existing" parameter is missing, which is expected behaviour, however the Evaluator will throw exception in case the custom context variable is missing.
So far I did very ugly fix, essentially disabling context variable validation
public Object visit(Expr.Variable variable) {
if (env == null) {
throw new Exceptions.RuntimeException(
variable.name,
'Error executing variable expression: no context was provided.'
);
}
if (env.contains(variable.name.lexeme)) {
return env.get(variable.name.lexeme);
} else {
return '';
}
}
Instead of throwing the exception. I have tried to explore the option to include new Configuration parameter, however the Interpreter class has no access to Configuration class and it's a lot of refactoring to propagate it all the way to the Interpreter plus I don't think it's a good pattern. I was thinking about having some flag in the Environment instead, but that also feels a bit dirty (like a custom Global Context variable for example).
Do you have some suggestion?
Thank you!
Hi,
first of all thanks for the great recent upgrades to the date handling and other improvements!
I am now dealing with specific scenario, where we are using expression for data transformation from incoming JSONs through endpoints. The issue is following:
Imagine we have following JSON:
For each record we provide the JSON as custom context, but in the second record the "non_existing" parameter is missing, which is expected behaviour, however the Evaluator will throw exception in case the custom context variable is missing.
So far I did very ugly fix, essentially disabling context variable validation
Instead of throwing the exception. I have tried to explore the option to include new Configuration parameter, however the Interpreter class has no access to Configuration class and it's a lot of refactoring to propagate it all the way to the Interpreter plus I don't think it's a good pattern. I was thinking about having some flag in the Environment instead, but that also feels a bit dirty (like a custom Global Context variable for example).
Do you have some suggestion?
Thank you!