diff --git a/src/main/java/org/apache/ibatis/reflection/property/PropertyNamer.java b/src/main/java/org/apache/ibatis/reflection/property/PropertyNamer.java index 2ec6920848b..78dba12ba16 100644 --- a/src/main/java/org/apache/ibatis/reflection/property/PropertyNamer.java +++ b/src/main/java/org/apache/ibatis/reflection/property/PropertyNamer.java @@ -15,7 +15,7 @@ */ package org.apache.ibatis.reflection.property; -import java.util.Locale; +import java.beans.Introspector; import org.apache.ibatis.reflection.ReflectionException; @@ -37,11 +37,7 @@ public static String methodToProperty(String name) { throw new ReflectionException("Error parsing property name '" + name + "'. Didn't start with 'is', 'get' or 'set'."); } - if (name.length() == 1 || (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) { - name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1); - } - - return name; + return Introspector.decapitalize(name); } public static boolean isProperty(String name) { diff --git a/src/test/java/org/apache/ibatis/reflection/property/PropertyNamerTest.java b/src/test/java/org/apache/ibatis/reflection/property/PropertyNamerTest.java new file mode 100644 index 00000000000..071212e9883 --- /dev/null +++ b/src/test/java/org/apache/ibatis/reflection/property/PropertyNamerTest.java @@ -0,0 +1,22 @@ +package org.apache.ibatis.reflection.property; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PropertyNamerTest { + + @Test + void methodToProperty() { + assertEquals("ok", PropertyNamer.methodToProperty("isOk")); + assertEquals("OK", PropertyNamer.methodToProperty("isOK")); + + assertEquals("name", PropertyNamer.methodToProperty("getName")); + assertEquals("XName", PropertyNamer.methodToProperty("getXName")); + assertEquals("xName", PropertyNamer.methodToProperty("getxName")); + + assertEquals("name", PropertyNamer.methodToProperty("setName")); + assertEquals("XName", PropertyNamer.methodToProperty("setXName")); + assertEquals("xName", PropertyNamer.methodToProperty("setxName")); + } +}