Skip to content

Commit 3f9ee4b

Browse files
committed
Move #2775 test to regular section, not failing
1 parent 78f609e commit 3f9ee4b

File tree

2 files changed

+30
-50
lines changed

2 files changed

+30
-50
lines changed

src/test/java/com/fasterxml/jackson/databind/jsontype/TestEnumTyping.java

+30-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
import com.fasterxml.jackson.annotation.*;
66

77
import com.fasterxml.jackson.databind.BaseMapTest;
8+
import com.fasterxml.jackson.databind.DeserializationFeature;
89
import com.fasterxml.jackson.databind.ObjectMapper;
910

1011
@SuppressWarnings("serial")
1112
public class TestEnumTyping extends BaseMapTest
1213
{
13-
/*
14-
/**********************************************************
15-
/* Helper types
16-
/**********************************************************
17-
*/
18-
1914
// note: As.WRAPPER_ARRAY worked initially; but as per [JACKSON-485], As.PROPERTY had issues
2015
@JsonTypeInfo(use=JsonTypeInfo.Id.MINIMAL_CLASS, include=JsonTypeInfo.As.PROPERTY)
2116
public interface EnumInterface { }
@@ -63,10 +58,23 @@ public EnumContaintingClass(ENUM_TYPE selected) {
6358
}
6459
}
6560

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+
6674
/*
67-
/**********************************************************
68-
/* Unit tests
69-
/**********************************************************
75+
/**********************************************************************
76+
/* Test methods
77+
/**********************************************************************
7078
*/
7179

7280
private final ObjectMapper MAPPER = newJsonMapper();
@@ -124,4 +132,17 @@ public void testRoundtrip() throws Exception
124132
Object o = MAPPER.readValue(json, EnumContaintingClass.class);
125133
assertNotNull(o);
126134
}
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+
}
127148
}

src/test/java/com/fasterxml/jackson/failing/PolymorphicEnum2775DeserTest.java

-41
This file was deleted.

0 commit comments

Comments
 (0)