Skip to content

Commit c8b071c

Browse files
jhoellerunknown
authored and
unknown
committed
Fixed BeanPropertyRowMapper to only prefix actual upper-case letters with underscores
Issue: SPR-10547
1 parent cd3d0c3 commit c8b071c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
import org.springframework.dao.InvalidDataAccessApiUsageException;
3838
import org.springframework.jdbc.support.JdbcUtils;
3939
import org.springframework.util.Assert;
40+
import org.springframework.util.StringUtils;
4041

4142
/**
4243
* {@link RowMapper} implementation that converts a row into a new instance
@@ -163,18 +164,19 @@ protected void initialize(Class<T> mappedClass) {
163164
* @return the converted name
164165
*/
165166
private String underscoreName(String name) {
167+
if (!StringUtils.hasLength(name)) {
168+
return "";
169+
}
166170
StringBuilder result = new StringBuilder();
167-
if (name != null && name.length() > 0) {
168-
result.append(name.substring(0, 1).toLowerCase());
169-
for (int i = 1; i < name.length(); i++) {
170-
String s = name.substring(i, i + 1);
171-
if (s.equals(s.toUpperCase())) {
172-
result.append("_");
173-
result.append(s.toLowerCase());
174-
}
175-
else {
176-
result.append(s);
177-
}
171+
result.append(name.substring(0, 1).toLowerCase());
172+
for (int i = 1; i < name.length(); i++) {
173+
String s = name.substring(i, i + 1);
174+
String slc = s.toLowerCase();
175+
if (!s.equals(slc)) {
176+
result.append("_").append(slc);
177+
}
178+
else {
179+
result.append(s);
178180
}
179181
}
180182
return result.toString();

0 commit comments

Comments
 (0)