Skip to content

Commit 2c3cad3

Browse files
committed
Added method on #1456 test to show that generic type resolution works when resolved through enclosing class
1 parent 21c38a9 commit 2c3cad3

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/builder/BuilderFailTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.databind.deser.builder;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import com.fasterxml.jackson.databind.*;
54
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
65
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package com.fasterxml.jackson.failing;
22

3-
4-
import com.fasterxml.jackson.databind.JavaType;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import org.junit.Test;
7-
83
import java.lang.reflect.Method;
94
import java.lang.reflect.Type;
105

11-
import static org.junit.Assert.assertEquals;
6+
import com.fasterxml.jackson.databind.*;
7+
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
8+
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
9+
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
1210

13-
public class GenericParameterTypeFactory1456Test {
11+
public class GenericParameterTypeFactory1456Test extends BaseMapTest
12+
{
1413
public static class BaseController<Entity extends BaseEntity> {
1514
public void process(Entity entity) {}
1615
}
@@ -21,12 +20,26 @@ public static class BaseEntity {}
2120

2221
public static class ImplEntity extends BaseEntity {}
2322

24-
@Test
25-
public void testGenericParameterHierarchy() throws NoSuchMethodException {
23+
private final ObjectMapper MAPPER = new ObjectMapper();
24+
25+
public void testGenericParameterDirect() throws Exception
26+
{
2627
Method proceed = BaseController.class.getMethod("process", BaseEntity.class);
2728
Type entityType = proceed.getGenericParameterTypes()[0];
2829

29-
JavaType resolvedType = new ObjectMapper().getTypeFactory().constructType(entityType, ImplController.class);
30+
JavaType resolvedType = MAPPER.getTypeFactory().constructType(entityType, ImplController.class);
3031
assertEquals(ImplEntity.class, resolvedType.getRawClass());
3132
}
33+
34+
public void testGenericParameterViaClass() throws Exception
35+
{
36+
BeanDescription desc = MAPPER.getDeserializationConfig().introspect(
37+
MAPPER.constructType(ImplController.class));
38+
AnnotatedClass ac = desc.getClassInfo();
39+
AnnotatedMethod m = ac.findMethod("process", new Class<?>[] { BaseEntity.class });
40+
assertNotNull(m);
41+
assertEquals(1, m.getParameterCount());
42+
AnnotatedParameter param = m.getParameter(0);
43+
assertEquals(ImplEntity.class, param.getType().getRawClass());
44+
}
3245
}

0 commit comments

Comments
 (0)