为什么PropertyPath构造函数中的propertyName不遵循Javabeans规范?

时间:2017-04-28 07:08:32

标签: java spring spring-data spring-data-commons

PropertyPath类的构造函数中的变量propertyName的名称似乎没有遵循JavaBeans规范(8.8推断名称的大写。)。

https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/mapping/PropertyPath.java

// PropertyPath Code: lines 73:
PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) {
...
    String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
...
}

代码表示当名称不匹配ALL_UPPERCASE时,第一个大写字母会更改为小写。

但JavaBeans规范说:

JavaBeans Specification

Thus when we extract a property or event name from the middle of an existing Java name, 
we normally convert the first character to lower case. 
However to support the occasional use of all upper-case names, we check if the first 
two characters of the name are both upper case and if so leave it alone. 
So for example,
    “FooBah” becomes “fooBah”
    “Z” becomes “z”
    “URL” becomes “URL”

例如: 如果我在类中有一个名为[MCount]的属性,则根据JavaBeans Specification,属性名称应为[MCount]。但是如果我使用[PropertyPath.from](它将调用PropertyPath构造函数)来获取属性,我将得到以下异常,因为属性名称已更改为[mCount]。

PropertyPath property = PropertyPath.from("MCount", classType);

例外:     java.lang.IllegalArgumentException:无法使用the找到Attribute     在此ManagedType [class]上给出名称[mCount] ...

任何人都有好的意见?谢谢!

1 个答案:

答案 0 :(得分:1)

the commit 0c4ed8a86a引入了此行为,以修复仅与所有大写属性名称相关的DATACMNS-257

如果您认为这是一个错误,请在the issue tracker

中提交