Skip to content

Instantly share code, notes, and snippets.

@danielfernandez
Created April 24, 2013 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielfernandez/5456537 to your computer and use it in GitHub Desktop.
Save danielfernandez/5456537 to your computer and use it in GitHub Desktop.
Testing the "class.name" expression in Spring. Fails with spring-expression 3.1.0, works alright in 3.2.0. Exception is: EL1008E:(pos 6): Field or property 'name' cannot be found on object of type 'testspringel.TestEL$TestObject'
package testspringel;
import java.util.Calendar;
import java.util.Date;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class TestEL {
public static void main(String[] args) {
try {
final SpelExpressionParser parser = new SpelExpressionParser();
final String spelExpression1 = "testDate.date";
final String spelExpression2 = "class";
final String spelExpression3 = "class.name";
final TestObject testObject = new TestObject();
testObject.setTestDate(Calendar.getInstance().getTime());
final StandardEvaluationContext context = new StandardEvaluationContext();
final SpelExpression exp1 = (SpelExpression) parser.parseExpression(spelExpression1);
final SpelExpression exp2 = (SpelExpression) parser.parseExpression(spelExpression2);
final SpelExpression exp3 = (SpelExpression) parser.parseExpression(spelExpression3);
final Object value1 = exp1.getValue(context, testObject);
System.out.println("Exp 1 returned: " + value1 + " [class: " + (value1 == null? null : value1.getClass().getName()) + "]");
final Object value2 = exp2.getValue(context, testObject);
System.out.println("Exp 2 returned: " + value2 + " [class: " + (value2 == null? null : value2.getClass().getName()) + "]");
final Object value3 = exp3.getValue(context, testObject);
System.out.println("Exp 3 returned: " + value3 + " [class: " + (value3 == null? null : value3.getClass().getName()) + "]");
} catch (final Exception e) {
e.printStackTrace();
}
}
public static class TestObject {
private Date testDate = null;
public TestObject() {
super();
}
public Date getTestDate() {
return this.testDate;
}
public void setTestDate(Date testDate) {
this.testDate = testDate;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment