Skip to content

Commit 5c86417

Browse files
committed
DATACMNS-1304 - PropertyPath now supports properties with all uppercase endings.
Backport of the changes applied to Lovelace and Kay. Original pull request: #289.
1 parent 394bd4c commit 5c86417

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.mapping;
1717

18+
import java.beans.Introspector;
1819
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.Iterator;
@@ -72,7 +73,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
7273
Assert.notNull(owningType, "Owning type must not be null!");
7374
Assert.notNull(base, "Perviously found properties must not be null!");
7475

75-
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
76+
String propertyName = Introspector.decapitalize(name);
7677
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
7778

7879
if (propertyType == null) {
@@ -356,7 +357,7 @@ private static PropertyPath create(String source, TypeInformation<?> type, Strin
356357
exception = e;
357358
}
358359

359-
Pattern pattern = Pattern.compile("\\p{Lu}+\\p{Ll}*$");
360+
Pattern pattern = Pattern.compile("\\p{Lu}\\p{Ll}*$");
360361
Matcher matcher = pattern.matcher(source);
361362

362363
if (matcher.find() && matcher.start() != 0) {

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ public void rejectsTooLongPath() {
364364
PropertyPath.from(path, Left.class);
365365
}
366366

367+
@Test // DATACMNS-1304
368+
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
369+
assertThat(from("categoryB", Product.class).toDotPath(), is("categoryB"));
370+
}
371+
372+
@Test // DATACMNS-1304
373+
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
374+
assertThat(from("categoryABId", Product.class).toDotPath(), is("categoryAB.id"));
375+
}
376+
377+
@Test // DATACMNS-1304
378+
public void detectsNestedSingleCharacterProperty() {
379+
assertThat(from("category_B", Product.class).toDotPath(), is("category.b"));
380+
}
381+
367382
private class Foo {
368383

369384
String userName;
@@ -407,4 +422,18 @@ private class Left {
407422
private class Right {
408423
Left bar;
409424
}
425+
426+
// DATACMNS-1304
427+
private class Product {
428+
Category category;
429+
Category categoryB;
430+
Category categoryAB;
431+
}
432+
433+
private class Category {
434+
B b;
435+
String id;
436+
}
437+
438+
private class B {}
410439
}

0 commit comments

Comments
 (0)