Refactor tests a bit
diff --git a/pom.xml b/pom.xml
index d7e882c..5e0c0af 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,18 +86,6 @@
<version>1.0.0</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <version>3.11.1</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<!-- Alas, need to include snapshot reference since otherwise can not find
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/GenericContent.java b/src/test/java/com/fasterxml/jackson/databind/deser/GenericContent.java
deleted file mode 100644
index 3ff6497..0000000
--- a/src/test/java/com/fasterxml/jackson/databind/deser/GenericContent.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.fasterxml.jackson.databind.deser;
-
-import java.util.Collection;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "_class")
-@JsonInclude(Include.NON_EMPTY)
-public class GenericContent {
-
- private Collection innerObjects;
-
- public Collection getInnerObjects() {
- return innerObjects;
- }
-
- public void setInnerObjects(Collection innerObjects) {
- this.innerObjects = innerObjects;
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/HandleUnknowTypeIdTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/HandleUnknowTypeIdTest.java
deleted file mode 100644
index 5e97e58..0000000
--- a/src/test/java/com/fasterxml/jackson/databind/deser/HandleUnknowTypeIdTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.fasterxml.jackson.databind.deser;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.commons.io.IOUtils;
-import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
-
-public class HandleUnknowTypeIdTest {
-
- public static class DummyContent {
- private String aField;
-
- public DummyContent() {
- super();
- }
-
- public DummyContent(String aField) {
- super();
- this.aField = aField;
- }
-
- public String getaField() {
- return aField;
- }
-
- public void setaField(String aField) {
- this.aField = aField;
- }
-
- @Override
- public String toString() {
- return "DummyContent [aField=" + aField + "]";
- }
- }
-
- private ObjectMapper objectMapper;
-
- @Before
- public void setUp() {
- objectMapper = new ObjectMapper();
- objectMapper.enableDefaultTyping();
- }
-
- @Test
- public void testDeserializationWithDeserializationProblemHandler() throws JsonParseException, JsonMappingException, IOException {
- String dummyJson = IOUtils.toString(HandleUnknowTypeIdTest.class.getResourceAsStream("/com/fasterxml/jackson/databind/deser/DummyProcessableContent.json"),
- StandardCharsets.UTF_8);
- objectMapper.addHandler(new DeserializationProblemHandler() {
- @Override
- public JavaType handleUnknownTypeId(DeserializationContext ctxt, JavaType baseType, String subTypeId, TypeIdResolver idResolver, String failureMsg) throws IOException {
- System.out.println("Print out a warning here");
- return ctxt.constructType(Void.class);
- }
- });
- GenericContent processableContent = objectMapper.readValue(dummyJson, GenericContent.class);
- Assertions.assertThat(processableContent.getInnerObjects()).hasSize(2).usingFieldByFieldElementComparator().contains(new DummyContent("some value"));
- }
-
- @Test
- public void testDeserializationWithFAIL_ON_INVALID_SUBTYPE_false() throws JsonParseException, JsonMappingException, IOException {
- String dummyJson = IOUtils.toString(HandleUnknowTypeIdTest.class.getResourceAsStream("/com/fasterxml/jackson/databind/deser/DummyProcessableContent.json"),
- StandardCharsets.UTF_8);
- objectMapper.disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE);
- GenericContent processableContent = objectMapper.readValue(dummyJson, GenericContent.class);
- Assertions.assertThat(processableContent.getInnerObjects()).hasSize(2).usingFieldByFieldElementComparator().contains(new DummyContent("some value"));
- }
-}
diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/filter/ProblemHandlerUnknownTypeId2221Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/filter/ProblemHandlerUnknownTypeId2221Test.java
new file mode 100644
index 0000000..7cd1b4a
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/databind/deser/filter/ProblemHandlerUnknownTypeId2221Test.java
@@ -0,0 +1,109 @@
+package com.fasterxml.jackson.databind.deser.filter;
+
+import java.io.*;
+import java.util.Collection;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
+import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
+
+// for [databind#2221]
+public class ProblemHandlerUnknownTypeId2221Test extends BaseMapTest
+{
+ @SuppressWarnings("rawtypes")
+ @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "_class")
+ @JsonInclude(Include.NON_EMPTY)
+ static class GenericContent {
+
+ private Collection innerObjects;
+
+ public Collection getInnerObjects() {
+ return innerObjects;
+ }
+
+ public void setInnerObjects(Collection innerObjects) {
+ this.innerObjects = innerObjects;
+ }
+ }
+
+ static class DummyContent {
+ private String aField;
+
+ public DummyContent() {
+ super();
+ }
+
+ public DummyContent(String aField) {
+ super();
+ this.aField = aField;
+ }
+
+ public String getaField() {
+ return aField;
+ }
+
+ public void setaField(String aField) {
+ this.aField = aField;
+ }
+
+ @Override
+ public String toString() {
+ return "DummyContent [aField=" + aField + "]";
+ }
+ }
+
+ private final static String CLASS_GENERIC_CONTENT = GenericContent.class.getName();
+ private final static String CLASS_DUMMY_CONTENT = DummyContent.class.getName();
+ private final static String JSON = aposToQuotes(
+"{\n" +
+" \"_class\":\""+CLASS_GENERIC_CONTENT+"\",\n" +
+" \"innerObjects\":\n" +
+" [\n" +
+" \"java.util.ArrayList\",\n" +
+" [\n" +
+" [\n" +
+" \""+CLASS_DUMMY_CONTENT+"\",\n" +
+" {\n" +
+" \"aField\":\"some value\"\n" +
+" }\n" +
+" ],\n" +
+" [\n" +
+" \"com.fasterxml.jackson.databind.deser.NoSuchClass$AnInventedClassBeingNotOnTheClasspath\",\n" +
+" {\n" +
+" \"aField\":\"some value\"\n" +
+" }\n" +
+" ]\n" +
+" ]\n" +
+" ]\n" +
+" }"
+);
+
+ public void testWithDeserializationProblemHandler() throws Exception {
+ final ObjectMapper mapper = new ObjectMapper()
+ .enableDefaultTyping();
+ mapper.addHandler(new DeserializationProblemHandler() {
+ @Override
+ public JavaType handleUnknownTypeId(DeserializationContext ctxt, JavaType baseType, String subTypeId, TypeIdResolver idResolver, String failureMsg) throws IOException {
+// System.out.println("Print out a warning here");
+ return ctxt.constructType(Void.class);
+ }
+ });
+ GenericContent processableContent = mapper.readValue(JSON, GenericContent.class);
+ assertNotNull(processableContent.getInnerObjects());
+ assertEquals(2, processableContent.getInnerObjects().size());
+ }
+
+ public void testWithDisabledFAIL_ON_INVALID_SUBTYPE() throws Exception {
+ final ObjectMapper mapper = new ObjectMapper()
+ .disable(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)
+ .enableDefaultTyping()
+ ;
+ GenericContent processableContent = mapper.readValue(JSON, GenericContent.class);
+ assertNotNull(processableContent.getInnerObjects());
+ assertEquals(2, processableContent.getInnerObjects().size());
+ }
+}