DATACMNS-1304 - PropertyPath now supports properties with all uppercase endings.
Backport of the changes applied to Lovelace and Kay. Original pull request: #289.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mapping;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -72,7 +73,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
|
||||
Assert.notNull(owningType, "Owning type must not be null!");
|
||||
Assert.notNull(base, "Perviously found properties must not be null!");
|
||||
|
||||
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
|
||||
String propertyName = Introspector.decapitalize(name);
|
||||
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
|
||||
|
||||
if (propertyType == null) {
|
||||
@@ -356,7 +357,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\p{Lu}+\\p{Ll}*$");
|
||||
Pattern pattern = Pattern.compile("\\p{Lu}\\p{Ll}*$");
|
||||
Matcher matcher = pattern.matcher(source);
|
||||
|
||||
if (matcher.find() && matcher.start() != 0) {
|
||||
|
||||
@@ -364,6 +364,21 @@ public class PropertyPathUnitTests {
|
||||
PropertyPath.from(path, Left.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
|
||||
assertThat(from("categoryB", Product.class).toDotPath(), is("categoryB"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
|
||||
assertThat(from("categoryABId", Product.class).toDotPath(), is("categoryAB.id"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void detectsNestedSingleCharacterProperty() {
|
||||
assertThat(from("category_B", Product.class).toDotPath(), is("category.b"));
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
String userName;
|
||||
@@ -407,4 +422,18 @@ public class PropertyPathUnitTests {
|
||||
private class Right {
|
||||
Left bar;
|
||||
}
|
||||
|
||||
// DATACMNS-1304
|
||||
private class Product {
|
||||
Category category;
|
||||
Category categoryB;
|
||||
Category categoryAB;
|
||||
}
|
||||
|
||||
private class Category {
|
||||
B b;
|
||||
String id;
|
||||
}
|
||||
|
||||
private class B {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user