|
5 | 5 | import com.fasterxml.jackson.annotation.*;
|
6 | 6 |
|
7 | 7 | import com.fasterxml.jackson.databind.BaseMapTest;
|
| 8 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
8 | 9 | import com.fasterxml.jackson.databind.ObjectMapper;
|
9 | 10 |
|
10 | 11 | @SuppressWarnings("serial")
|
11 | 12 | public class TestEnumTyping extends BaseMapTest
|
12 | 13 | {
|
13 |
| - /* |
14 |
| - /********************************************************** |
15 |
| - /* Helper types |
16 |
| - /********************************************************** |
17 |
| - */ |
18 |
| - |
19 | 14 | // note: As.WRAPPER_ARRAY worked initially; but as per [JACKSON-485], As.PROPERTY had issues
|
20 | 15 | @JsonTypeInfo(use=JsonTypeInfo.Id.MINIMAL_CLASS, include=JsonTypeInfo.As.PROPERTY)
|
21 | 16 | public interface EnumInterface { }
|
@@ -63,10 +58,23 @@ public EnumContaintingClass(ENUM_TYPE selected) {
|
63 | 58 | }
|
64 | 59 | }
|
65 | 60 |
|
| 61 | + // [databind#2775] |
| 62 | + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME |
| 63 | +// work-around: |
| 64 | +// , include = JsonTypeInfo.As.WRAPPER_ARRAY |
| 65 | + ) |
| 66 | + @JsonSubTypes(@JsonSubTypes.Type(TestEnum2775.class)) |
| 67 | + interface Base2775 {} |
| 68 | + |
| 69 | + @JsonTypeName("Test") |
| 70 | + enum TestEnum2775 implements Base2775 { |
| 71 | + VALUE; |
| 72 | + } |
| 73 | + |
66 | 74 | /*
|
67 |
| - /********************************************************** |
68 |
| - /* Unit tests |
69 |
| - /********************************************************** |
| 75 | + /********************************************************************** |
| 76 | + /* Test methods |
| 77 | + /********************************************************************** |
70 | 78 | */
|
71 | 79 |
|
72 | 80 | private final ObjectMapper MAPPER = newJsonMapper();
|
@@ -124,4 +132,17 @@ public void testRoundtrip() throws Exception
|
124 | 132 | Object o = MAPPER.readValue(json, EnumContaintingClass.class);
|
125 | 133 | assertNotNull(o);
|
126 | 134 | }
|
| 135 | + |
| 136 | + // [databind#2775] |
| 137 | + public void testEnumAsSubtypeNoFailOnInvalidTypeId() throws Exception |
| 138 | + { |
| 139 | + final Base2775 testValue = TestEnum2775.VALUE; |
| 140 | + String json = MAPPER.writeValueAsString(testValue); |
| 141 | +//System.err.println("JSON: "+json); |
| 142 | + |
| 143 | + Base2775 deserializedValue = MAPPER.readerFor(Base2775.class) |
| 144 | + .without(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE) |
| 145 | + .readValue(json); |
| 146 | + assertEquals(testValue, deserializedValue); |
| 147 | + } |
127 | 148 | }
|
0 commit comments