Is there anyway using OGNL to access private variables that aren't exposed as a bean property (ie no get
/set
method pair)? I wanted to use OGNL as a faster, cleaner method of reflection for use in unit tests.
Here is my code:
@Test
public void shouldSetup() throws OgnlException{
class A{
private Object b = "foo";
private Object c = "bar";
public Object getB(){ return b; }
}
A a = new A();
System.out.println( "This'll work..." );
Ognl.getValue( "b", a );
System.out.println( "...and this'll fail..." );
Ognl.getValue( "c", a );
System.out.println( "...and we'll never get here." );
}
Aucun commentaire:
Enregistrer un commentaire