|
2 | 2 |
|
3 | 3 | import java.util.*;
|
4 | 4 |
|
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | +import com.fasterxml.jackson.annotation.JsonProperty; |
5 | 7 | import com.fasterxml.jackson.core.Version;
|
6 | 8 | import com.fasterxml.jackson.databind.BaseMapTest;
|
7 | 9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
@@ -38,10 +40,48 @@ public static class AbstractImpl implements Abstract {
|
38 | 40 | public int getValue() { return 3; }
|
39 | 41 | }
|
40 | 42 |
|
| 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 | + |
41 | 81 | /*
|
42 |
| - /********************************************************** |
| 82 | + /********************************************************************** |
43 | 83 | /* Test methods
|
44 |
| - /********************************************************** |
| 84 | + /********************************************************************** |
45 | 85 | */
|
46 | 86 |
|
47 | 87 | public void testCollectionDefaulting() throws Exception
|
@@ -115,4 +155,23 @@ public void testInterfaceDefaulting() throws Exception
|
115 | 155 | Abstract a = mapper.readValue("{}", Abstract.class);
|
116 | 156 | assertNotNull(a);
|
117 | 157 | }
|
| 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 | + } |
118 | 177 | }
|
0 commit comments