简体   繁体   中英

Spring expression parsing using evaluation context for boolean field

I am using spring-expression for parsing values in a class(present in jar). After i read this value i set it in the target class [a typical use case of spring-expression]. However, all the field's value from the class in jar can be parsed except, boolean value. In the source class, it is declared like this:

boolean isVerified;

//getter
public isVerified() {
  return isVerfied;
}

Spring-expression code to read this value:

Expression sourceExp = parser.parseExpression(<source field string>);
sourceExp.getValue(sourceContext);

and this fails. The message is Couldn't find property isVerified

My question is it because spring is looking for isIsVerified method rather than isVerified method? If not this what could be the reason for failure?

You don't show your expression but SpEL uses JavaBean semantics when accessing bean properties. It knows nothing about the internals of the referenced bean. When it encounters a property request...

"x.foo"

it tries to find the getter getFoo() (any return type) and if that's not found, it looks for isFoo() if it returns boolean.

I suspect you are trying to use x.isVerified . There is no such getter; you need to use x.verified , or you can invoke the method itself x.isVerified() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM