Skip to content

Commit 2c2816f

Browse files
committed
fixes #581 Another case which requires special treatment for type parameters.
1 parent a2cf7d4 commit 2c2816f

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

src/main/java/org/apache/ibatis/reflection/MetaClass.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 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.
@@ -119,12 +119,12 @@ private Type getGenericGetterType(String propertyName) {
119119
Field _method = MethodInvoker.class.getDeclaredField("method");
120120
_method.setAccessible(true);
121121
Method method = (Method) _method.get(invoker);
122-
return method.getGenericReturnType();
122+
return TypeParameterResolver.resolveReturnType(method, reflector.getType());
123123
} else if (invoker instanceof GetFieldInvoker) {
124124
Field _field = GetFieldInvoker.class.getDeclaredField("field");
125125
_field.setAccessible(true);
126126
Field field = (Field) _field.get(invoker);
127-
return field.getGenericType();
127+
return TypeParameterResolver.resolveFieldType(field, reflector.getType());
128128
}
129129
} catch (NoSuchFieldException e) {
130130
} catch (IllegalAccessException e) {

src/test/java/org/apache/ibatis/submitted/simplelistparameter/CarMapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 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.
@@ -23,4 +23,10 @@ public interface CarMapper {
2323

2424
@Select({ "select name from car where doors = #{doors[1]}" })
2525
List<Car> getCar(Car car);
26+
27+
@Select({ "select name from car where doors = #{doors1[1]}" })
28+
List<Rv> getRv1(Rv rv);
29+
30+
@Select({ "select name from car where doors = #{doors2[1]}" })
31+
List<Rv> getRv2(Rv rv);
2632
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.simplelistparameter;
17+
18+
public class Rv extends Vehicle<String> {
19+
}

src/test/java/org/apache/ibatis/submitted/simplelistparameter/SimpleListParameterTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 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.
@@ -65,4 +65,31 @@ public void shouldGetACar() throws Exception {
6565
}
6666
}
6767

68+
@Test
69+
public void shouldResolveGenericFieldGetterType() throws Exception {
70+
SqlSession sqlSession = sqlSessionFactory.openSession();
71+
try {
72+
CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
73+
Rv rv = new Rv();
74+
rv.doors1 = Arrays.asList(new String[] {"2", "4"});
75+
List<Rv> rvs = carMapper.getRv1(rv);
76+
Assert.assertNotNull(rvs);
77+
} finally {
78+
sqlSession.close();
79+
}
80+
}
81+
82+
@Test
83+
public void shouldResolveGenericMethodGetterType() throws Exception {
84+
SqlSession sqlSession = sqlSessionFactory.openSession();
85+
try {
86+
CarMapper carMapper = sqlSession.getMapper(CarMapper.class);
87+
Rv rv = new Rv();
88+
rv.setDoors2(Arrays.asList(new String[] {"2", "4"}));
89+
List<Rv> rvs = carMapper.getRv2(rv);
90+
Assert.assertNotNull(rvs);
91+
} finally {
92+
sqlSession.close();
93+
}
94+
}
6895
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright 2009-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.submitted.simplelistparameter;
17+
18+
import java.util.List;
19+
20+
public class Vehicle<T> {
21+
public T name;
22+
23+
public List<T> doors1;
24+
25+
private List<T> doors2;
26+
27+
public List<T> getDoors2() {
28+
return doors2;
29+
}
30+
31+
public void setDoors2(List<T> doors2) {
32+
this.doors2 = doors2;
33+
}
34+
}

0 commit comments

Comments
 (0)