@Test public void cleanExpression() { assertEquals("test", evaluator.cleanExpression(MVEL_ESCAPE_SYMBOL + "test")); assertEquals(" test", evaluator.cleanExpression(MVEL_ESCAPE_SYMBOL + " test")); assertEquals(" " + MVEL_ESCAPE_SYMBOL + " test", evaluator.cleanExpression(MVEL_ESCAPE_SYMBOL + " " + MVEL_ESCAPE_SYMBOL + " test")); assertEquals("test", evaluator.cleanExpression(new TextNode(MVEL_ESCAPE_SYMBOL + "test").toString())); assertEquals(" test", evaluator.cleanExpression(new TextNode(MVEL_ESCAPE_SYMBOL + " test").toString())); assertEquals(" " + MVEL_ESCAPE_SYMBOL + " test", evaluator.cleanExpression(new TextNode(MVEL_ESCAPE_SYMBOL + " " + MVEL_ESCAPE_SYMBOL + " test").toString())); assertThatThrownBy(() -> evaluator.cleanExpression("test")) .isInstanceOf(IllegalArgumentException.class) .hasMessageStartingWith("Malformed MVEL expression"); assertThatThrownBy(() -> evaluator.cleanExpression(new TextNode("test").toString())) .isInstanceOf(IllegalArgumentException.class) .hasMessageStartingWith("Malformed MVEL expression"); }
protected String cleanExpression(String rawExpression) { if (rawExpression != null && rawExpression.trim().startsWith(MVEL_ESCAPE_SYMBOL)) { return rawExpression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } Optional<JsonNode> optionalJSONNode = JsonUtils.convertFromStringToJSONNode(rawExpression); if (optionalJSONNode.isPresent()) { JsonNode jsonNode = optionalJSONNode.get(); if (jsonNode.isTextual() && jsonNode.asText() != null && jsonNode.asText().trim().startsWith(MVEL_ESCAPE_SYMBOL)) { String expression = jsonNode.asText(); return expression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } } throw new IllegalArgumentException(MALFORMED_MVEL_EXPRESSION + "'" + rawExpression + "'"); }
MVELExpressionEvaluator implements ExpressionEvaluator { protected String cleanExpression(String rawExpression) { if (rawExpression != null && rawExpression.trim().startsWith(MVEL_ESCAPE_SYMBOL)) { return rawExpression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } Optional<JsonNode> optionalJSONNode = JsonUtils.convertFromStringToJSONNode(rawExpression); if (optionalJSONNode.isPresent()) { JsonNode jsonNode = optionalJSONNode.get(); if (jsonNode.isTextual() && jsonNode.asText() != null && jsonNode.asText().trim().startsWith(MVEL_ESCAPE_SYMBOL)) { String expression = jsonNode.asText(); return expression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } } throw new IllegalArgumentException(MALFORMED_MVEL_EXPRESSION + "'" + rawExpression + "'"); } }
MVELExpressionEvaluator implements ExpressionEvaluator { protected String cleanExpression(String rawExpression) { if (rawExpression != null && rawExpression.trim().startsWith(MVEL_ESCAPE_SYMBOL)) { return rawExpression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } Optional<JsonNode> optionalJSONNode = JsonUtils.convertFromStringToJSONNode(rawExpression); if (optionalJSONNode.isPresent()) { JsonNode jsonNode = optionalJSONNode.get(); if (jsonNode.isTextual() && jsonNode.asText() != null && jsonNode.asText().trim().startsWith(MVEL_ESCAPE_SYMBOL)) { String expression = jsonNode.asText(); return expression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } } throw new IllegalArgumentException(MALFORMED_MVEL_EXPRESSION + "'" + rawExpression + "'"); } MVELExpressionEvaluator(ClassLoader classLoader); }
MVELExpressionEvaluator implements ExpressionEvaluator { protected String cleanExpression(String rawExpression) { if (rawExpression != null && rawExpression.trim().startsWith(MVEL_ESCAPE_SYMBOL)) { return rawExpression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } Optional<JsonNode> optionalJSONNode = JsonUtils.convertFromStringToJSONNode(rawExpression); if (optionalJSONNode.isPresent()) { JsonNode jsonNode = optionalJSONNode.get(); if (jsonNode.isTextual() && jsonNode.asText() != null && jsonNode.asText().trim().startsWith(MVEL_ESCAPE_SYMBOL)) { String expression = jsonNode.asText(); return expression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } } throw new IllegalArgumentException(MALFORMED_MVEL_EXPRESSION + "'" + rawExpression + "'"); } MVELExpressionEvaluator(ClassLoader classLoader); @Override boolean evaluateUnaryExpression(String rawExpression, Object resultValue, Class<?> resultClass); @Override Object evaluateLiteralExpression(String rawExpression, String className, List<String> genericClasses); @Override String fromObjectToExpression(Object value); }
MVELExpressionEvaluator implements ExpressionEvaluator { protected String cleanExpression(String rawExpression) { if (rawExpression != null && rawExpression.trim().startsWith(MVEL_ESCAPE_SYMBOL)) { return rawExpression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } Optional<JsonNode> optionalJSONNode = JsonUtils.convertFromStringToJSONNode(rawExpression); if (optionalJSONNode.isPresent()) { JsonNode jsonNode = optionalJSONNode.get(); if (jsonNode.isTextual() && jsonNode.asText() != null && jsonNode.asText().trim().startsWith(MVEL_ESCAPE_SYMBOL)) { String expression = jsonNode.asText(); return expression.replaceFirst(MVEL_ESCAPE_SYMBOL, ""); } } throw new IllegalArgumentException(MALFORMED_MVEL_EXPRESSION + "'" + rawExpression + "'"); } MVELExpressionEvaluator(ClassLoader classLoader); @Override boolean evaluateUnaryExpression(String rawExpression, Object resultValue, Class<?> resultClass); @Override Object evaluateLiteralExpression(String rawExpression, String className, List<String> genericClasses); @Override String fromObjectToExpression(Object value);  }