-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4ae368
commit 24de8a2
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/com/fasterxml/jackson/failing/AbstracTypeMapping1186Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
public class AbstracTypeMapping1186Test extends BaseMapTest | ||
{ | ||
public interface IContainer<T> { | ||
@JsonProperty("ts") | ||
List<T> getTs(); | ||
} | ||
|
||
static class MyContainer<T> implements IContainer<T> { | ||
|
||
final List<T> ts; | ||
|
||
@JsonCreator | ||
public MyContainer(@JsonProperty("ts") List<T> ts) { | ||
this.ts = ts; | ||
} | ||
|
||
@Override | ||
public List<T> getTs() { | ||
return ts; | ||
} | ||
} | ||
|
||
public static class MyObject { | ||
public String msg; | ||
} | ||
|
||
public void testDeserializeMyContainer() throws Exception { | ||
Module module = new SimpleModule().addAbstractTypeMapping(IContainer.class, MyContainer.class); | ||
final ObjectMapper mapper = new ObjectMapper().registerModule(module); | ||
String json = "{\"ts\": [ { \"msg\": \"hello\"} ] }"; | ||
final Object o = mapper.readValue(json, | ||
mapper.getTypeFactory().constructParametricType(IContainer.class, MyObject.class)); | ||
assertEquals(MyContainer.class, o.getClass()); | ||
MyContainer<?> myc = (MyContainer<?>) o; | ||
assertEquals(1, myc.ts.size()); | ||
Object value = myc.ts.get(0); | ||
assertEquals(MyObject.class, value.getClass()); | ||
} | ||
} |