Skip to content

Commit

Permalink
Fix #725
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 16, 2015
1 parent 3686421 commit fad4726
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Project: jackson-databind
(reported by Charles A)
#700: Cannot Change Default Abstract Type Mapper from LinkedHashMap
(reported by wealdtech@github)
#725: Auto-detect multi-argument constructor with implicit names if it is the only visible creator
- Remove old cglib compatibility tests; cause problems in Eclipse

2.5.2 (not yet released)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import java.util.concurrent.atomic.AtomicReference;

import com.fasterxml.jackson.annotation.JsonCreator;

import com.fasterxml.jackson.core.JsonLocation;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.DeserializerFactoryConfig;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.deser.impl.CreatorCollector;
import com.fasterxml.jackson.databind.deser.std.*;
import com.fasterxml.jackson.databind.ext.OptionalHandlerFactory;
Expand All @@ -19,11 +20,7 @@
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
import com.fasterxml.jackson.databind.util.NameTransformer;
import com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition;
import com.fasterxml.jackson.databind.util.TokenBuffer;
import com.fasterxml.jackson.databind.util.*;

/**
* Abstract factory base class that can provide deserializers for standard
Expand Down Expand Up @@ -495,10 +492,18 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(ctor, isCreator, properties);
} else if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
continue;
}
if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// Secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(ctor, isCreator, properties);
} else { // otherwise, epic fail
continue;
}
// otherwise, epic fail?
// 16-Mar-2015, tatu: due to [#725], need to be more permissive. For now let's
// only report problem if there's no implicit name
PropertyName impl = _findImplicitParamName(nonAnnotatedParam, intr);
if (impl == null || impl.isEmpty()) {
// Let's consider non-static inner class as a special case...
int ix = nonAnnotatedParam.getIndex();
if ((ix == 0) && ClassUtil.isNonStaticInnerClass(ctor.getDeclaringClass())) {
Expand All @@ -508,7 +513,6 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
throw new IllegalArgumentException("Argument #"+ix
+" of constructor "+ctor+" has no property name annotation; must have name when multiple-parameter constructor annotated as Creator");
}
continue;
}
// [#725]: as a fallback, all-implicit names may work as well
if (!creators.hasDefaultCreator()) {
Expand All @@ -518,7 +522,6 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
implicitCtors.add(ctor);
}
}

// last option, as per [#725]: consider implicit-names-only, visible constructor,
// if just one found
if ((implicitCtors != null) && !creators.hasDelegatingCreator()
Expand Down Expand Up @@ -546,7 +549,6 @@ protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
continue;
}
// as per earlier notes, only end up here if no properties associated with creator

final int argCount = ctor.getParameterCount();
CreatorProperty[] properties = new CreatorProperty[argCount];
for (int i = 0; i < argCount; ++i) {
Expand Down Expand Up @@ -889,21 +891,20 @@ protected PropertyName _findParamName(AnnotatedParameter param, AnnotationIntros
return null;
}

@Deprecated // in 2.6, remove from 2.7
protected PropertyName _findExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
protected PropertyName _findImplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
return intr.findNameForDeserialization(param);
String str = intr.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
}
return null;
}

@Deprecated // in 2.6, remove from 2.7
protected PropertyName _findImplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
protected PropertyName _findExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
String str = intr.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
if (param != null && intr != null) {
return intr.findNameForDeserialization(param);
}
return null;
}
Expand All @@ -917,7 +918,7 @@ protected boolean _hasExplicitParamName(AnnotatedParameter param, AnnotationIntr
}
return false;
}

/*
/**********************************************************
/* JsonDeserializerFactory impl: array deserializers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class POJOPropertiesCollector
/* Configuration
/**********************************************************
*/

/**
* Configuration settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void testMultiArgWithPartialOverride() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new MyParamIntrospector());
MultiArgCtorBean bean = mapper.readValue(aposToQuotes("{'b2':7, 'c':222, 'a':-99}"),
MultiArgCtorBean.class);
MultiArgCtorBeanWithAnnotations bean = mapper.readValue(aposToQuotes("{'b2':7, 'c':222, 'a':-99}"),
MultiArgCtorBeanWithAnnotations.class);
assertNotNull(bean);
assertEquals(7, bean._b);
assertEquals(-99, bean._a);
Expand Down

0 comments on commit fad4726

Please sign in to comment.