Manual merge of fix for #2785 (from PR #2786)
diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x
index 5b6520b..b80e73d 100644
--- a/release-notes/CREDITS-2.x
+++ b/release-notes/CREDITS-2.x
@@ -1131,3 +1131,8 @@
* Reported #2759: Rearranging of props when property-based generator is in use leads
to incorrect output
(2.11.1)
+
+Joshua Shannon (retrodaredevil@github)
+ * Reported, contributed fix for #2785: Polymorphic subtypes not registering on copied
+ ObjectMapper (2.11.1)
+ (2.11.2)
diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x
index ca0e604..3e37b74 100644
--- a/release-notes/VERSION-2.x
+++ b/release-notes/VERSION-2.x
@@ -8,6 +8,8 @@
#2783: Parser/Generator features not set when using `ObjectMapper.createParser()`,
`createGenerator()`
+#2785: Polymorphic subtypes not registering on copied ObjectMapper (2.11.1)
+ (reported, fix contributed by Joshua S)
2.11.1 (25-Jun-2020)
diff --git a/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java b/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java
index 0744700..08977d3 100644
--- a/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java
+++ b/src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java
@@ -116,13 +116,13 @@
/**
* Copy-constructor used for making a copy used by new {@link ObjectMapper}.
*
- * @since 2.9
+ * @since 2.11.2
*/
protected DeserializationConfig(DeserializationConfig src,
- SimpleMixInResolver mixins, RootNameLookup rootNames,
+ SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides)
{
- super(src, mixins, rootNames, configOverrides);
+ super(src, str, mixins, rootNames, configOverrides);
_deserFeatures = src._deserFeatures;
_problemHandlers = src._problemHandlers;
_nodeFactory = src._nodeFactory;
@@ -132,6 +132,18 @@
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
}
+ /**
+ * @since 2.9
+ * @deprecated since 2.11.2
+ */
+ @Deprecated
+ protected DeserializationConfig(DeserializationConfig src,
+ SimpleMixInResolver mixins, RootNameLookup rootNames,
+ ConfigOverrides configOverrides)
+ {
+ this(src, src._subtypeResolver, mixins, rootNames, configOverrides);
+ }
+
/*
/**********************************************************
/* Life-cycle, secondary constructors to support
diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
index ef1afb5..45b6373 100644
--- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
+++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
@@ -565,9 +565,9 @@
RootNameLookup rootNames = new RootNameLookup();
_serializationConfig = new SerializationConfig(src._serializationConfig,
- _mixIns, rootNames, _configOverrides);
+ _subtypeResolver, _mixIns, rootNames, _configOverrides);
_deserializationConfig = new DeserializationConfig(src._deserializationConfig,
- _mixIns, rootNames, _configOverrides);
+ _subtypeResolver, _mixIns, rootNames, _configOverrides);
_serializerProvider = src._serializerProvider.copy();
_deserializationContext = src._deserializationContext.copy();
diff --git a/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java b/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java
index f644837..b5a9d94 100644
--- a/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java
+++ b/src/main/java/com/fasterxml/jackson/databind/SerializationConfig.java
@@ -128,13 +128,13 @@
/**
* Copy-constructor used for making a copy to be used by new {@link ObjectMapper}.
*
- * @since 2.9
+ * @since 2.11.2
*/
protected SerializationConfig(SerializationConfig src,
- SimpleMixInResolver mixins, RootNameLookup rootNames,
+ SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides)
{
- super(src, mixins, rootNames, configOverrides);
+ super(src, str, mixins, rootNames, configOverrides);
_serFeatures = src._serFeatures;
_filterProvider = src._filterProvider;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
@@ -144,6 +144,18 @@
_formatWriteFeaturesToChange = src._formatWriteFeaturesToChange;
}
+ /**
+ * @since 2.9
+ * @deprecated since 2.11.2
+ */
+ @Deprecated
+ protected SerializationConfig(SerializationConfig src,
+ SimpleMixInResolver mixins, RootNameLookup rootNames,
+ ConfigOverrides configOverrides)
+ {
+ this(src, src._subtypeResolver, mixins, rootNames, configOverrides);
+ }
+
/*
/**********************************************************
/* Life-cycle, secondary constructors to support
diff --git a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java
index 044d13b..2514e8e 100644
--- a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java
+++ b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java
@@ -137,17 +137,17 @@
* Copy constructor usually called to make a copy for use by
* ObjectMapper that is copied.
*
- * @since 2.8
+ * @since 2.11.2
*/
protected MapperConfigBase(MapperConfigBase<CFG,T> src,
- SimpleMixInResolver mixins, RootNameLookup rootNames,
+ SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides)
{
// 18-Apr-2018, tatu: [databind#1898] need to force copying of `ClassIntrospector`
// (to clear its cache) to avoid leakage
super(src, src._base.copy());
_mixIns = mixins;
- _subtypeResolver = src._subtypeResolver;
+ _subtypeResolver = str;
_rootNames = rootNames;
_rootName = src._rootName;
_view = src._view;
diff --git a/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java b/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java
index 5f4cffb..7e39256 100644
--- a/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/ObjectMapperTest.java
@@ -7,6 +7,8 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSetter;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
@@ -51,7 +53,16 @@
@SuppressWarnings("serial")
static class NoCopyMapper extends ObjectMapper { }
- final ObjectMapper MAPPER = new ObjectMapper();
+ // [databind#2785]
+ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY,
+ property = "packetType")
+ public interface Base2785 {
+ }
+ @JsonTypeName("myType")
+ static class Impl2785 implements Base2785 {
+ }
+
+ private final ObjectMapper MAPPER = newJsonMapper();
/*
/**********************************************************
@@ -185,6 +196,14 @@
assertSame(customVis, config2.getDefaultVisibilityChecker());
}
+ // [databind#2785]
+ public void testCopyOfSubtypeResolver2785() throws Exception {
+ ObjectMapper objectMapper = new ObjectMapper().copy();
+ objectMapper.registerSubtypes(Impl2785.class);
+ Object result = objectMapper.readValue("{ \"packetType\": \"myType\" }", Base2785.class);
+ assertNotNull(result);
+ }
+
public void testFailedCopy() throws Exception
{
NoCopyMapper src = new NoCopyMapper();