fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.LinkedHashMap;
  4. import java.util.Map;
  5.  
  6. import junit.framework.Assert;
  7.  
  8. import org.junit.Test;
  9. import org.springframework.expression.EvaluationContext;
  10. import org.springframework.expression.Expression;
  11. import org.springframework.expression.ExpressionParser;
  12. import org.springframework.expression.spel.standard.SpelExpressionParser;
  13. import org.springframework.expression.spel.support.StandardEvaluationContext;
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Map<String,Object> map = new LinkedHashMap();
  21. map.put("uri", "http:");
  22. Map nameMap = new LinkedHashMap();
  23. nameMap.put("givenName", "Arthur");
  24. map.put("value", nameMap);
  25.  
  26. EvaluationContext ctx = new StandardEvaluationContext(map);
  27. ExpressionParser parser = new SpelExpressionParser();
  28. String el1 = "#root['value'].get('givenName')";
  29. Expression exp = parser.parseExpression(el1);
  30. Object evaluated = exp.getValue(ctx);
  31. Assert.assertEquals("Arthur", evaluated);
  32.  
  33. String el2 = "#root['value']['givenName']";
  34. exp = parser.parseExpression(el2);
  35. evaluated = exp.getValue(ctx);
  36. }
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: package org.springframework.expression does not exist
import org.springframework.expression.EvaluationContext;
                                     ^
Main.java:10: error: package org.springframework.expression does not exist
import org.springframework.expression.Expression;
                                     ^
Main.java:11: error: package org.springframework.expression does not exist
import org.springframework.expression.ExpressionParser;
                                     ^
Main.java:12: error: package org.springframework.expression.spel.standard does not exist
import org.springframework.expression.spel.standard.SpelExpressionParser;
                                                   ^
Main.java:13: error: package org.springframework.expression.spel.support does not exist
import org.springframework.expression.spel.support.StandardEvaluationContext;
                                                  ^
Main.java:26: error: cannot find symbol
        EvaluationContext ctx = new StandardEvaluationContext(map);
        ^
  symbol:   class EvaluationContext
  location: class Ideone
Main.java:26: error: cannot find symbol
        EvaluationContext ctx = new StandardEvaluationContext(map);
                                    ^
  symbol:   class StandardEvaluationContext
  location: class Ideone
Main.java:27: error: cannot find symbol
        ExpressionParser parser = new SpelExpressionParser();
        ^
  symbol:   class ExpressionParser
  location: class Ideone
Main.java:27: error: cannot find symbol
        ExpressionParser parser = new SpelExpressionParser();
                                      ^
  symbol:   class SpelExpressionParser
  location: class Ideone
Main.java:29: error: cannot find symbol
        Expression exp = parser.parseExpression(el1);
        ^
  symbol:   class Expression
  location: class Ideone
Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
10 errors
stdout
Standard output is empty