1 package com.fasterxml.jackson.databind.jsontype; 2 3 import java.util.List; 4 5 import com.fasterxml.jackson.annotation.*; 6 import com.fasterxml.jackson.databind.*; 7 import com.fasterxml.jackson.databind.module.SimpleModule; 8 9 public class AbstractTypeMapping1186Test extends BaseMapTest 10 { 11 public interface IContainer<T> { 12 @JsonProperty("ts") getTs()13 List<T> getTs(); 14 } 15 16 static class MyContainer<T> implements IContainer<T> { 17 18 final List<T> ts; 19 20 @JsonCreator MyContainer(@sonProperty"ts") List<T> ts)21 public MyContainer(@JsonProperty("ts") List<T> ts) { 22 this.ts = ts; 23 } 24 25 @Override getTs()26 public List<T> getTs() { 27 return ts; 28 } 29 } 30 31 public static class MyObject { 32 public String msg; 33 } 34 testDeserializeMyContainer()35 public void testDeserializeMyContainer() throws Exception { 36 SimpleModule module = new SimpleModule().addAbstractTypeMapping(IContainer.class, MyContainer.class); 37 final ObjectMapper mapper = new ObjectMapper().registerModule(module); 38 String json = "{\"ts\": [ { \"msg\": \"hello\"} ] }"; 39 final Object o = mapper.readValue(json, 40 mapper.getTypeFactory().constructParametricType(IContainer.class, MyObject.class)); 41 assertEquals(MyContainer.class, o.getClass()); 42 MyContainer<?> myc = (MyContainer<?>) o; 43 assertEquals(1, myc.ts.size()); 44 Object value = myc.ts.get(0); 45 assertEquals(MyObject.class, value.getClass()); 46 } 47 } 48