Skip to content

Commit fce8326

Browse files
committed
Add failing test for #2019
1 parent 57f5e70 commit fce8326

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

src/test/java/com/fasterxml/jackson/databind/module/TestAbstractTypes.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.*;
44

5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
57
import com.fasterxml.jackson.core.Version;
68
import com.fasterxml.jackson.databind.BaseMapTest;
79
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -38,10 +40,48 @@ public static class AbstractImpl implements Abstract {
3840
public int getValue() { return 3; }
3941
}
4042

43+
// [databind#2019]: mappings from multiple modules
44+
public interface Datatype1 {
45+
String getValue();
46+
}
47+
48+
public interface Datatype2 {
49+
String getValue();
50+
}
51+
52+
static class SimpleDatatype1 implements Datatype1 {
53+
54+
private final String value;
55+
56+
@JsonCreator
57+
public SimpleDatatype1(@JsonProperty("value") String value) {
58+
this.value = value;
59+
}
60+
61+
@Override
62+
public String getValue() {
63+
return value;
64+
}
65+
}
66+
67+
static class SimpleDatatype2 implements Datatype2 {
68+
private final String value;
69+
70+
@JsonCreator
71+
public SimpleDatatype2(@JsonProperty("value") String value) {
72+
this.value = value;
73+
}
74+
75+
@Override
76+
public String getValue() {
77+
return value;
78+
}
79+
}
80+
4181
/*
42-
/**********************************************************
82+
/**********************************************************************
4383
/* Test methods
44-
/**********************************************************
84+
/**********************************************************************
4585
*/
4686

4787
public void testCollectionDefaulting() throws Exception
@@ -115,4 +155,23 @@ public void testInterfaceDefaulting() throws Exception
115155
Abstract a = mapper.readValue("{}", Abstract.class);
116156
assertNotNull(a);
117157
}
158+
159+
// [databind#2019]: mappings from multiple modules
160+
public static void testAbstractMappingsFromTwoModules() throws Exception
161+
{
162+
ObjectMapper mapper = newObjectMapper();
163+
SimpleModule module1 = new SimpleModule("module1");
164+
module1.addAbstractTypeMapping(Datatype1.class, SimpleDatatype1.class);
165+
166+
SimpleModule module2 = new SimpleModule("module2");
167+
module2.addAbstractTypeMapping(Datatype2.class, SimpleDatatype2.class);
168+
mapper.registerModules(module1, module2);
169+
170+
final String JSON_EXAMPLE = "{\"value\": \"aaa\"}";
171+
Datatype1 value1 = mapper.readValue(JSON_EXAMPLE, Datatype1.class);
172+
assertNotNull(value1);
173+
174+
Datatype2 value2 = mapper.readValue(JSON_EXAMPLE, Datatype2.class);
175+
assertNotNull(value2);
176+
}
118177
}

0 commit comments

Comments
 (0)