mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-25 10:22:17 -05:00
Fix return of primitive types by removing explicit cast, add tests to prevent regressions
This commit is contained in:
parent
117910274e
commit
2dec1ea7cf
@ -143,6 +143,7 @@ public class RowToObjectMapper<T> extends RowMapper {
|
|||||||
*
|
*
|
||||||
* @return An object instance.
|
* @return An object instance.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
public T mapRowToReturnType() {
|
public T mapRowToReturnType() {
|
||||||
|
|
||||||
if (resultSetConstructor)
|
if (resultSetConstructor)
|
||||||
@ -195,7 +196,7 @@ public class RowToObjectMapper<T> extends RowMapper {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
|
if (typeId != TypeMappingsFactory.TYPE_UNKNOWN) {
|
||||||
return _returnTypeClass.cast(extractColumnValue(1, typeId));
|
return (T)extractColumnValue(1, typeId);
|
||||||
} else {
|
} else {
|
||||||
// we still might want a single value (i.e. java.util.Date)
|
// we still might want a single value (i.e. java.util.Date)
|
||||||
Object val = extractColumnValue(1, typeId);
|
Object val = extractColumnValue(1, typeId);
|
||||||
|
@ -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));
|
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() {
|
private List<Map<String, String>> getListMap() {
|
||||||
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();
|
final List<Map<String, String>> arrayMap = new ArrayList<Map<String, String>>();
|
||||||
|
Loading…
Reference in New Issue
Block a user