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:
Oliver Gierke
2018-06-05 18:48:20 +02:00
parent 394bd4c6da
commit 5c86417a2d
2 changed files with 32 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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 {}
}