|
| 1 | +package com.fasterxml.jackson.failing; |
| 2 | + |
| 3 | +import java.lang.reflect.Method; |
| 4 | +import java.lang.reflect.Type; |
| 5 | + |
| 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; |
| 10 | + |
| 11 | +public class GenericParameterTypeFactory1456Test extends BaseMapTest |
| 12 | +{ |
| 13 | + public static class BaseController<Entity extends BaseEntity> { |
| 14 | + public void process(Entity entity) {} |
| 15 | + } |
| 16 | + |
| 17 | + public static class ImplController extends BaseController<ImplEntity> {} |
| 18 | + |
| 19 | + public static class BaseEntity {} |
| 20 | + |
| 21 | + public static class ImplEntity extends BaseEntity {} |
| 22 | + |
| 23 | + private final ObjectMapper MAPPER = new ObjectMapper(); |
| 24 | + |
| 25 | + public void testGenericParameterDirect() throws Exception |
| 26 | + { |
| 27 | + Method proceed = BaseController.class.getMethod("process", BaseEntity.class); |
| 28 | + Type entityType = proceed.getGenericParameterTypes()[0]; |
| 29 | + |
| 30 | + JavaType resolvedType = MAPPER.getTypeFactory().constructType(entityType, ImplController.class); |
| 31 | + assertEquals(ImplEntity.class, resolvedType.getRawClass()); |
| 32 | + } |
| 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 | + } |
| 45 | +} |
0 commit comments