diff --git a/src/main/java/org/springframework/data/mapping/PropertyPath.java b/src/main/java/org/springframework/data/mapping/PropertyPath.java index 0d8f3ea99..0ed8167f7 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -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 { 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 { 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) { diff --git a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java index 429796f58..bb8344d7b 100644 --- a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java @@ -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 {} }