Skip to content

Commit

Permalink
Handle numbers underscore separation when mapping camelCase containin…
Browse files Browse the repository at this point in the history
…g a number to snake_case
  • Loading branch information
LE FAUCHEUR Brieuc committed Oct 31, 2024
1 parent b9ac2cc commit 81ab792
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ public static String convertPropertyNameToUnderscoreName(@Nullable String name)
if (Character.isUpperCase(c)) {
result.append('_').append(Character.toLowerCase(c));
}
else if (Character.isDigit(c) && !Character.isDigit(name.charAt(i - 1))) {
result.append('_').append(c);
}
else {
result.append(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ void convertUnderscoreNameToPropertyName() {
assertThat(JdbcUtils.convertUnderscoreNameToPropertyName("some_name_with_1_digit")).isEqualTo("someNameWith1Digit");
}

@Test
void convertPropertyNameToUnderscoreName() {
assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("AName")).isEqualTo("a_name");
assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someoneElsesName")).isEqualTo("someone_elses_name");
assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someNameWith1Digit")).isEqualTo("some_name_with_1_digit");
assertThat(JdbcUtils.convertPropertyNameToUnderscoreName("someNameWith12Number")).isEqualTo("some_name_with_12_number");
}
}

0 comments on commit 81ab792

Please sign in to comment.