diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 3e77eacfc2..e80c26bbf8 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -780,3 +780,7 @@ Jakub Skierbiszewski (jskierbi@github) * Reported, contributed fix for #2001: Deserialization issue with `@JsonIgnore` and `@JsonCreator` + `@JsonProperty` for same property name (2.9.6) + +Carter Kozak (cakofony@github) + * Reported #2016: Delegating JsonCreator disregards JsonDeserialize info + (2.9.6) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 80c90ddd74..ee58d0daf7 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -21,6 +21,8 @@ Project: jackson-databind #2001: Deserialization issue with `@JsonIgnore` and `@JsonCreator` + `@JsonProperty` for same property name (reported, fix contributed by Jakub S) +#2016: Delegating JsonCreator disregards JsonDeserialize info + (reported by Carter K) #2019: Abstract Type mapping in 2.9 fails when multiple modules are registered (reported by asger82@github) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java index 6450733287..3cf861c640 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java @@ -275,7 +275,8 @@ public ValueInstantiator findValueInstantiator(DeserializationContext ctxt, if (instantiator.getIncompleteParameter() != null) { final AnnotatedParameter nonAnnotatedParam = instantiator.getIncompleteParameter(); final AnnotatedWithParams ctor = nonAnnotatedParam.getOwner(); - throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex()+" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator"); + throw new IllegalArgumentException("Argument #"+nonAnnotatedParam.getIndex() + +" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator"); } return instantiator; @@ -2143,36 +2144,6 @@ protected JavaType modifyTypeByAnnotation(DeserializationContext ctxt, if (intr == null) { return type; } - - // First, deserializers for key/value types? - /* - if (type.isMapLikeType()) { - JavaType keyType = type.getKeyType(); - // 21-Mar-2011, tatu: ... and associated deserializer too (unless already assigned) - // (not 100% why or how, but this does seem to get called more than once, which - // is not good: for now, let's just avoid errors) - if (keyType != null && keyType.getValueHandler() == null) { - Object kdDef = intr.findKeyDeserializer(a); - KeyDeserializer kd = ctxt.keyDeserializerInstance(a, kdDef); - if (kd != null) { - type = (T) ((MapLikeType) type).withKeyValueHandler(kd); - keyType = type.getKeyType(); // just in case it's used below - } - } - } - JavaType contentType = type.getContentType(); - if (contentType != null) { - // ... as well as deserializer for contents: - if (contentType.getValueHandler() == null) { // as with above, avoid resetting (which would trigger exception) - Object cdDef = intr.findContentDeserializer(a); - JsonDeserializer cd = ctxt.deserializerInstance(a, cdDef); - if (cd != null) { - type = (T) type.withContentValueHandler(cd); - } - } - } - */ - // then: type refinement(s)? return intr.refineDeserializationType(ctxt.getConfig(), a, type); } diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java b/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java index ae9dede3fe..1b204b6ea1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java @@ -68,8 +68,6 @@ public class CreatorCollector { protected SettableBeanProperty[] _propertyBasedArgs; - protected AnnotatedParameter _incompleteParameter; - /* /********************************************************** /* Life-cycle @@ -83,11 +81,12 @@ public CreatorCollector(BeanDescription beanDesc, MapperConfig config) { .isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS); } - public ValueInstantiator constructValueInstantiator( - DeserializationConfig config) { - final JavaType delegateType = _computeDelegateType( + public ValueInstantiator constructValueInstantiator(DeserializationConfig config) + throws JsonMappingException + { + final JavaType delegateType = _computeDelegateType(config, _creators[C_DELEGATE], _delegateArgs); - final JavaType arrayDelegateType = _computeDelegateType( + final JavaType arrayDelegateType = _computeDelegateType(config, _creators[C_ARRAY_DELEGATE], _arrayDelegateArgs); final JavaType type = _beanDesc.getType(); @@ -108,7 +107,6 @@ public ValueInstantiator constructValueInstantiator( inst.configureFromLongCreator(_creators[C_LONG]); inst.configureFromDoubleCreator(_creators[C_DOUBLE]); inst.configureFromBooleanCreator(_creators[C_BOOLEAN]); - inst.configureIncompleteParameter(_incompleteParameter); return inst; } @@ -193,12 +191,6 @@ public void addPropertyCreator(AnnotatedWithParams creator, } } - public void addIncompeteParameter(AnnotatedParameter parameter) { - if (_incompleteParameter == null) { - _incompleteParameter = parameter; - } - } - /* /********************************************************** /* Accessors @@ -232,8 +224,10 @@ public boolean hasPropertyBasedCreator() { /********************************************************** */ - private JavaType _computeDelegateType(AnnotatedWithParams creator, - SettableBeanProperty[] delegateArgs) { + private JavaType _computeDelegateType(MapperConfig config, + AnnotatedWithParams creator, SettableBeanProperty[] delegateArgs) + throws JsonMappingException + { if (!_hasNonDefaultCreator || (creator == null)) { return null; } @@ -247,7 +241,11 @@ private JavaType _computeDelegateType(AnnotatedWithParams creator, } } } - return creator.getParameterType(ix); + // 03-May-2018, tatu: [databind#2016] need to check possible annotation-based + // type refinement(s) + JavaType baseType = creator.getParameterType(ix); + return config.getAnnotationIntrospector().refineDeserializationType(config, + creator.getParameter(ix), baseType); } private T _fixAccess(T member) { diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java index 5ce7bcd302..3d112e489d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java @@ -509,8 +509,7 @@ protected JsonMappingException rewrapCtorProblem(DeserializationContext ctxt, /********************************************************** */ - private Object _createUsingDelegate( - AnnotatedWithParams delegateCreator, + private Object _createUsingDelegate(AnnotatedWithParams delegateCreator, SettableBeanProperty[] delegateArguments, DeserializationContext ctxt, Object delegate) diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java index 4c92d5a060..2d13f39523 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolution1964Test.java @@ -39,7 +39,7 @@ public void testTypeCompatibility1964() throws Exception { // Important! Must use raw type since assignment requires effectively // casting due incompatible type parameters. - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) Map> repoPrivilegesMap = new CustomMap(); String key = "/storages/storage0/releases"; Collection values = new HashSet<>();