简体   繁体   English

使用评估上下文对布尔字段进行Spring表达式解析

[英]Spring expression parsing using evaluation context for boolean field

I am using spring-expression for parsing values in a class(present in jar). 我正在使用spring-expression解析类(存在于jar中)中的值。 After i read this value i set it in the target class [a typical use case of spring-expression]. 读取此值后,将其设置在目标类中[spring-expression的典型使用情况]。 However, all the field's value from the class in jar can be parsed except, boolean value. 但是,可以解析jar中类中所有字段的值,布尔值除外。 In the source class, it is declared like this: 在源类中,它的声明如下:

boolean isVerified;

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

Spring-expression code to read this value: Spring表达式代码读取此值:

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

and this fails. 这失败了。 The message is Couldn't find property isVerified 消息是找不到属性isVerified

My question is it because spring is looking for isIsVerified method rather than isVerified method? 我的问题是因为s​​pring正在寻找isIsVerified方法而不是isVerified方法? 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. 您没有显示您的表达式,但是SpEL在访问bean属性时使用JavaBean语义。 It knows nothing about the internals of the referenced bean. 它对所引用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. 它将尝试找到getter getFoo() (任何返回类型),如果未找到,则返回isFoo()如果它返回布尔值)。

I suspect you are trying to use x.isVerified . 我怀疑您正在尝试使用x.isVerified There is no such getter; 没有这样的吸气剂。 you need to use x.verified , or you can invoke the method itself x.isVerified() . 您需要使用x.verified ,也可以调用方法本身x.isVerified()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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