Fix return of primitive types by removing explicit cast, add tests to prevent regressions

This commit is contained in:
moparisthebest 2014-06-25 12:10:12 -04:00
parent 117910274e
commit 2dec1ea7cf
2 changed files with 14 additions and 1 deletions

View File

@ -143,6 +143,7 @@ public class RowToObjectMapper<T> extends RowMapper {
*
* @return An object instance.
*/
@SuppressWarnings({"unchecked"})
public T mapRowToReturnType() {
if (resultSetConstructor)
@ -195,7 +196,7 @@ public class RowToObjectMapper<T> extends RowMapper {
try {
if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
return _returnTypeClass.cast(extractColumnValue(1, typeId));
return (T)extractColumnValue(1, typeId);
} else {
// we still might want a single value (i.e. java.util.Date)
Object val = extractColumnValue(1, typeId);

View File

@ -221,6 +221,18 @@ public class QueryMapperTest {
Assert.assertEquals(map, qm.toMap("SELECT person_no AS first_no, person_no AS last_no FROM person WHERE person_no < 4", Long.class, Long.class));
}
@Test
public void testSelectLongObject() throws Throwable {
final Long expected = fieldPerson1.getPersonNo();
Assert.assertEquals(expected, qm.toObject("SELECT person_no FROM person WHERE person_no = ?", Long.class, expected));
}
@Test
public void testSelectLongPrimitive() throws Throwable {
final Long expected = fieldPerson1.getPersonNo();
Assert.assertEquals(expected, qm.toObject("SELECT person_no FROM person WHERE person_no = ?", long.class, expected));
}
private List<Map<String, String>> getListMap() {
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();