Skip to content

Commit ac82499

Browse files
committed
Fix #2021
1 parent fa240dd commit ac82499

File tree

8 files changed

+52
-18
lines changed

8 files changed

+52
-18
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Project: jackson-databind
2525
(reported by Carter K)
2626
#2019: Abstract Type mapping in 2.9 fails when multiple modules are registered
2727
(reported by asger82@github)
28+
#2021: Delegating JsonCreator disregards `JsonDeserialize.using` annotation
2829
#2023: `JsonFormat.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT` not working
2930
with `null` coercion with `@JsonSetter`
3031

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
339339
if (beanDesc.getType().isConcrete()) {
340340
_addDeserializerConstructors(ctxt, beanDesc, vchecker, intr, creators, creatorDefs);
341341
}
342-
return creators.constructValueInstantiator(config);
342+
return creators.constructValueInstantiator(ctxt);
343343
}
344344

345345
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(DeserializationContext ctxt,

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,26 +617,33 @@ protected void _replaceProperty(BeanPropertyMap props, SettableBeanProperty[] cr
617617
}
618618
}
619619

620-
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt, JavaType delegateType,
621-
AnnotatedWithParams delegateCreator) throws JsonMappingException {
620+
@SuppressWarnings("unchecked")
621+
private JsonDeserializer<Object> _findDelegateDeserializer(DeserializationContext ctxt,
622+
JavaType delegateType, AnnotatedWithParams delegateCreator) throws JsonMappingException
623+
{
622624
// Need to create a temporary property to allow contextual deserializers:
623625
BeanProperty.Std property = new BeanProperty.Std(TEMP_PROPERTY_NAME,
624626
delegateType, null, delegateCreator,
625627
PropertyMetadata.STD_OPTIONAL);
626-
627628
TypeDeserializer td = delegateType.getTypeHandler();
628629
if (td == null) {
629630
td = ctxt.getConfig().findTypeDeserializer(delegateType);
630631
}
631-
JsonDeserializer<Object> dd = findDeserializer(ctxt, delegateType, property);
632+
// 04-May-2018, tatu: [databind#2021] check if there's custom deserializer attached
633+
// to type (resolved from parameter)
634+
JsonDeserializer<Object> dd = delegateType.getValueHandler();
635+
if (dd == null) {
636+
dd = findDeserializer(ctxt, delegateType, property);
637+
} else {
638+
dd = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(dd, property, delegateType);
639+
}
632640
if (td != null) {
633641
td = td.forProperty(property);
634642
return new TypeWrappedDeserializer(td, dd);
635643
}
636644
return dd;
637645
}
638646

639-
640647
/**
641648
* Helper method that can be used to see if specified property is annotated
642649
* to indicate use of a converter for property value (in case of container types,

src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ public CreatorCollector(BeanDescription beanDesc, MapperConfig<?> config) {
8181
.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS);
8282
}
8383

84-
public ValueInstantiator constructValueInstantiator(DeserializationConfig config)
84+
public ValueInstantiator constructValueInstantiator(DeserializationContext ctxt)
8585
throws JsonMappingException
8686
{
87-
final JavaType delegateType = _computeDelegateType(config,
87+
final DeserializationConfig config = ctxt.getConfig();
88+
final JavaType delegateType = _computeDelegateType(ctxt,
8889
_creators[C_DELEGATE], _delegateArgs);
89-
final JavaType arrayDelegateType = _computeDelegateType(config,
90+
final JavaType arrayDelegateType = _computeDelegateType(ctxt,
9091
_creators[C_ARRAY_DELEGATE], _arrayDelegateArgs);
9192
final JavaType type = _beanDesc.getType();
9293

@@ -224,7 +225,7 @@ public boolean hasPropertyBasedCreator() {
224225
/**********************************************************
225226
*/
226227

227-
private JavaType _computeDelegateType(MapperConfig<?> config,
228+
private JavaType _computeDelegateType(DeserializationContext ctxt,
228229
AnnotatedWithParams creator, SettableBeanProperty[] delegateArgs)
229230
throws JsonMappingException
230231
{
@@ -241,11 +242,28 @@ private JavaType _computeDelegateType(MapperConfig<?> config,
241242
}
242243
}
243244
}
244-
// 03-May-2018, tatu: [databind#2016] need to check possible annotation-based
245-
// type refinement(s)
245+
final DeserializationConfig config = ctxt.getConfig();
246+
247+
// 03-May-2018, tatu: need to check possible annotation-based
248+
// custom deserializer [databind#2012],
249+
// type refinement(s) [databind#2016].
246250
JavaType baseType = creator.getParameterType(ix);
247-
return config.getAnnotationIntrospector().refineDeserializationType(config,
248-
creator.getParameter(ix), baseType);
251+
AnnotationIntrospector intr = config.getAnnotationIntrospector();
252+
if (intr != null) {
253+
AnnotatedParameter delegate = creator.getParameter(ix);
254+
255+
// First: custom deserializer(s):
256+
Object deserDef = intr.findDeserializer(delegate);
257+
if (deserDef != null) {
258+
JsonDeserializer<Object> deser = ctxt.deserializerInstance(delegate, deserDef);
259+
baseType = baseType.withValueHandler(deser);
260+
} else {
261+
// Second: type refinement(s), if no explicit deserializer was located
262+
baseType = intr.refineDeserializationType(config,
263+
delegate, baseType);
264+
}
265+
}
266+
return baseType;
249267
}
250268

251269
private <T extends AnnotatedMember> T _fixAccess(T member) {

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,15 +997,21 @@ protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Prop prop,
997997
@Override
998998
public PropertyName findNameForSerialization(Annotated a)
999999
{
1000+
boolean useDefault = false;
10001001
JsonGetter jg = _findAnnotation(a, JsonGetter.class);
10011002
if (jg != null) {
1002-
return PropertyName.construct(jg.value());
1003+
String s = jg.value();
1004+
// 04-May-2018, tatu: Should allow for "nameless" `@JsonGetter` too
1005+
if (!s.isEmpty()) {
1006+
return PropertyName.construct(s);
1007+
}
1008+
useDefault = true;
10031009
}
10041010
JsonProperty pann = _findAnnotation(a, JsonProperty.class);
10051011
if (pann != null) {
10061012
return PropertyName.construct(pann.value());
10071013
}
1008-
if (_hasOneOf(a, ANNOTATIONS_TO_INFER_SER)) {
1014+
if (useDefault || _hasOneOf(a, ANNOTATIONS_TO_INFER_SER)) {
10091015
return PropertyName.USE_DEFAULT;
10101016
}
10111017
return null;

src/test/java/com/fasterxml/jackson/databind/creators/DelegatingArrayCreator1804Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingArrayCreator1804Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.databind.creators;
1+
package com.fasterxml.jackson.databind.deser.creators;
22

33
import java.util.List;
44

src/test/java/com/fasterxml/jackson/failing/DelegatingCreatorAnnotations2021Test.java renamed to src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorAnnotations2021Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.deser.creators;
22

33
import java.io.IOException;
44

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
public class NullConversionWithCreatorTest extends BaseMapTest
88
{
9+
// [databind#2024]
910
static class EmptyFromNullViaCreator {
1011
Point p;
1112

@@ -24,6 +25,7 @@ public EmptyFromNullViaCreator(@JsonSetter(nulls=Nulls.AS_EMPTY)
2425
*/
2526
private final ObjectMapper MAPPER = newObjectMapper();
2627

28+
// [databind#2024]
2729
public void testEmptyFromNullViaCreator() throws Exception
2830
{
2931
EmptyFromNullViaCreator result = MAPPER.readValue(aposToQuotes("{'p':null}"),

0 commit comments

Comments
 (0)