Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9017

Allow SpEL to resolve getter method against object of type Class

    Details

    • Last commented by a User:
      true

      Description

      If your context object is a Class<?> then you cannot evaluate an expression that calls a getter on that object.

      For example:

          /**
           * WORKS
           */
          public void testSpelGetterOnBean() {
              final String name = "foo";
              final Object thing = new Object() {
                  public String getName() { return name; }
              };
              
              final ExpressionParser parser = new SpelExpressionParser();
              final StandardEvaluationContext context = new StandardEvaluationContext(thing);
              final Object result = parser.parseExpression("name").getValue(context);
      
              assertEquals(name, result);
          }
      
          /**
           * FAILS
           */
          public void testSpelGetterOnClass() {
              final Class<?> clazz = Object.class;
              final String name = clazz.getName();
              
              final ExpressionParser parser = new SpelExpressionParser();
              final StandardEvaluationContext context = new StandardEvaluationContext(clazz);
              final Object result = parser.parseExpression("name").getValue(context);
      
              assertEquals(name, result);
          }
      

        Attachments

          Activity

            People

            • Assignee:
              pwebb Phil Webb
              Reporter:
              gregor Gregor Purdy
              Last updater:
              Chris Beams
            • Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 39 weeks, 2 days ago