Skip to content

Commit 63216c9

Browse files
committed
Modify #881 a bit, to remove dependency on CreatorProperty type
1 parent ed98f34 commit 63216c9

File tree

10 files changed

+83
-70
lines changed

10 files changed

+83
-70
lines changed

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.6.1 (not yet released)
8+
9+
#881: BeanDeserializerBase having issues with non-CreatorProperty properties.
10+
(reported by dharaburda@github)
11+
712
2.6.0 (19-Jul-2015)
813

914
#77: Allow injection of 'transient' fields

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
422422
boolean useProps = _checkIfCreatorPropertyBased(intr, ctor, argDef);
423423

424424
if (useProps) {
425-
CreatorProperty[] properties = new CreatorProperty[1];
425+
SettableBeanProperty[] properties = new SettableBeanProperty[1];
426426
PropertyName name = (argDef == null) ? null : argDef.getFullName();
427427
AnnotatedParameter arg = ctor.getParameter(0);
428428
properties[0] = constructCreatorProperty(ctxt, beanDesc, name, 0, arg,
@@ -447,7 +447,7 @@ public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig config
447447
// do, with some constraints. But that will require bit post processing...
448448

449449
AnnotatedParameter nonAnnotatedParam = null;
450-
CreatorProperty[] properties = new CreatorProperty[argCount];
450+
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
451451
int explicitNameCount = 0;
452452
int implicitWithCreatorCount = 0;
453453
int injectCount = 0;
@@ -536,7 +536,7 @@ protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
536536
List<AnnotatedConstructor> implicitCtors) throws JsonMappingException
537537
{
538538
AnnotatedConstructor found = null;
539-
CreatorProperty[] foundProps = null;
539+
SettableBeanProperty[] foundProps = null;
540540

541541
// Further checks: (a) must have names for all parameters, (b) only one visible
542542
// Also, since earlier matching of properties and creators relied on existence of
@@ -549,7 +549,7 @@ protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
549549
}
550550
// as per earlier notes, only end up here if no properties associated with creator
551551
final int argCount = ctor.getParameterCount();
552-
CreatorProperty[] properties = new CreatorProperty[argCount];
552+
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
553553
for (int i = 0; i < argCount; ++i) {
554554
final AnnotatedParameter param = ctor.getParameter(i);
555555
final PropertyName name = _findParamName(param, intr);
@@ -573,7 +573,7 @@ protected void _checkImplicitlyNamedConstructors(DeserializationContext ctxt,
573573
creators.addPropertyCreator(found, /*isCreator*/ false, foundProps);
574574
BasicBeanDescription bbd = (BasicBeanDescription) beanDesc;
575575
// Also: add properties, to keep error messages complete wrt known properties...
576-
for (CreatorProperty prop : foundProps) {
576+
for (SettableBeanProperty prop : foundProps) {
577577
PropertyName pn = prop.getFullName();
578578
if (!bbd.hasProperty(pn)) {
579579
BeanPropertyDefinition newDef = SimpleBeanPropertyDefinition.construct(
@@ -698,7 +698,7 @@ protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
698698
}
699699
// 1 or more args; all params must have name annotations
700700
AnnotatedParameter nonAnnotatedParam = null;
701-
CreatorProperty[] properties = new CreatorProperty[argCount];
701+
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
702702
int implicitNameCount = 0;
703703
int explicitNameCount = 0;
704704
int injectCount = 0;
@@ -817,7 +817,7 @@ protected boolean _handleSingleArgumentFactory(DeserializationConfig config,
817817
* a logical property passed via Creator (constructor or static
818818
* factory method)
819819
*/
820-
protected CreatorProperty constructCreatorProperty(DeserializationContext ctxt,
820+
protected SettableBeanProperty constructCreatorProperty(DeserializationContext ctxt,
821821
BeanDescription beanDesc, PropertyName name, int index,
822822
AnnotatedParameter param,
823823
Object injectableValueId)
@@ -861,7 +861,7 @@ protected CreatorProperty constructCreatorProperty(DeserializationContext ctxt,
861861
}
862862
// Note: contextualization of typeDeser _should_ occur in constructor of CreatorProperty
863863
// so it is not called directly here
864-
CreatorProperty prop = new CreatorProperty(name, type, property.getWrapperName(),
864+
SettableBeanProperty prop = new CreatorProperty(name, type, property.getWrapperName(),
865865
typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId,
866866
metadata);
867867
if (deser != null) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public void resolve(DeserializationContext ctxt)
481481
// 18-May-2015, tatu: _Should_ start with consistent set. But can we really
482482
// fully count on this? May need to revisit in future; seems to hold for now.
483483
for (int i = 0, len = creatorProps.length; i < len; ++i) {
484-
if (creatorProps[i] == origProp && prop instanceof CreatorProperty) {
484+
if (creatorProps[i] == origProp) {
485485
creatorProps[i] = prop;
486486
break;
487487
}
@@ -496,9 +496,8 @@ public void resolve(DeserializationContext ctxt)
496496
}
497497
}
498498
}
499-
500-
// one more thing: if this property uses "external property" type inclusion
501-
// (see [JACKSON-453]), it needs different handling altogether
499+
// one more thing: if this property uses "external property" type inclusion,
500+
// it needs different handling altogether
502501
if (prop.hasValueTypeDeserializer()) {
503502
TypeDeserializer typeDeser = prop.getValueTypeDeserializer();
504503
if (typeDeser.getTypeInclusion() == JsonTypeInfo.As.EXTERNAL_PROPERTY) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ protected void addBeanProps(DeserializationContext ctxt,
532532
CreatorProperty cprop = null;
533533
if (creatorProps != null) {
534534
for (SettableBeanProperty cp : creatorProps) {
535-
if (name.equals(cp.getName())) {
535+
if (name.equals(cp.getName()) && (cp instanceof CreatorProperty)) {
536536
cprop = (CreatorProperty) cp;
537537
break;
538538
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public boolean canInstantiate() {
115115
* NOTE: all properties will be of type
116116
* {@link com.fasterxml.jackson.databind.deser.CreatorProperty}.
117117
*/
118-
public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) { return null; }
118+
public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
119+
return null;
120+
}
119121

120122
/**
121123
* Method that can be used to determine what is the type of delegate

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fasterxml.jackson.databind.DeserializationContext;
1010
import com.fasterxml.jackson.databind.JavaType;
1111
import com.fasterxml.jackson.databind.deser.CreatorProperty;
12+
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
1213
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
1314
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
1415
import com.fasterxml.jackson.databind.introspect.*;
@@ -60,9 +61,9 @@ public class CreatorCollector
6061
protected boolean _hasNonDefaultCreator = false;
6162

6263
// when there are injectable values along with delegate:
63-
protected CreatorProperty[] _delegateArgs;
64+
protected SettableBeanProperty[] _delegateArgs;
6465

65-
protected CreatorProperty[] _propertyBasedArgs;
66+
protected SettableBeanProperty[] _propertyBasedArgs;
6667

6768
protected AnnotatedParameter _incompleteParameter;
6869

@@ -171,14 +172,14 @@ public void addBooleanCreator(AnnotatedWithParams creator, boolean explicit) {
171172
}
172173

173174
public void addDelegatingCreator(AnnotatedWithParams creator, boolean explicit,
174-
CreatorProperty[] injectables)
175+
SettableBeanProperty[] injectables)
175176
{
176177
verifyNonDup(creator, C_DELEGATE, explicit);
177178
_delegateArgs = injectables;
178179
}
179180

180181
public void addPropertyCreator(AnnotatedWithParams creator, boolean explicit,
181-
CreatorProperty[] properties)
182+
SettableBeanProperty[] properties)
182183
{
183184
verifyNonDup(creator, C_PROPS, explicit);
184185
// [JACKSON-470] Better ensure we have no duplicate names either...

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
1212
import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
1313

14-
public class ObjectIdReferenceProperty extends SettableBeanProperty {
14+
public class ObjectIdReferenceProperty extends SettableBeanProperty
15+
{
1516
private static final long serialVersionUID = 1L;
1617

1718
private final SettableBeanProperty _forward;
@@ -57,6 +58,11 @@ public AnnotatedMember getMember() {
5758
return _forward.getMember();
5859
}
5960

61+
@Override
62+
public int getCreatorIndex() {
63+
return _forward.getCreatorIndex();
64+
}
65+
6066
@Override
6167
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException {
6268
deserializeSetAndReturn(p, ctxt, instance);

src/main/java/com/fasterxml/jackson/databind/deser/std/JsonLocationInstantiator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.databind.PropertyMetadata;
88
import com.fasterxml.jackson.databind.PropertyName;
99
import com.fasterxml.jackson.databind.deser.CreatorProperty;
10+
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
1011
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
1112

1213
/**
@@ -25,10 +26,10 @@ public String getValueTypeDesc() {
2526
public boolean canCreateFromObjectWith() { return true; }
2627

2728
@Override
28-
public CreatorProperty[] getFromObjectArguments(DeserializationConfig config) {
29+
public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
2930
JavaType intType = config.constructType(Integer.TYPE);
3031
JavaType longType = config.constructType(Long.TYPE);
31-
return new CreatorProperty[] {
32+
return new SettableBeanProperty[] {
3233
creatorProp("sourceRef", config.constructType(Object.class), 0),
3334
creatorProp("byteOffset", longType, 1),
3435
creatorProp("charOffset", longType, 2),
@@ -55,4 +56,4 @@ private final static long _long(Object o) {
5556
private final static int _int(Object o) {
5657
return (o == null) ? 0 : ((Number) o).intValue();
5758
}
58-
}
59+
}

src/main/java/com/fasterxml/jackson/databind/deser/std/StdValueInstantiator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class StdValueInstantiator
3737
// // // With-args (property-based) construction
3838

3939
protected AnnotatedWithParams _withArgsCreator;
40-
protected CreatorProperty[] _constructorArguments;
40+
protected SettableBeanProperty[] _constructorArguments;
4141

4242
// // // Delegate construction
4343

4444
protected JavaType _delegateType;
4545
protected AnnotatedWithParams _delegateCreator;
46-
protected CreatorProperty[] _delegateArguments;
46+
protected SettableBeanProperty[] _delegateArguments;
4747

4848
// // // Scalar construction
4949

@@ -100,8 +100,8 @@ protected StdValueInstantiator(StdValueInstantiator src)
100100
* three), and clear other properties
101101
*/
102102
public void configureFromObjectSettings(AnnotatedWithParams defaultCreator,
103-
AnnotatedWithParams delegateCreator, JavaType delegateType, CreatorProperty[] delegateArgs,
104-
AnnotatedWithParams withArgsCreator, CreatorProperty[] constructorArgs)
103+
AnnotatedWithParams delegateCreator, JavaType delegateType, SettableBeanProperty[] delegateArgs,
104+
AnnotatedWithParams withArgsCreator, SettableBeanProperty[] constructorArgs)
105105
{
106106
_defaultCreator = defaultCreator;
107107
_delegateCreator = delegateCreator;
@@ -247,7 +247,7 @@ public Object createUsingDelegate(DeserializationContext ctxt, Object delegate)
247247
final int len = _delegateArguments.length;
248248
Object[] args = new Object[len];
249249
for (int i = 0; i < len; ++i) {
250-
CreatorProperty prop = _delegateArguments[i];
250+
SettableBeanProperty prop = _delegateArguments[i];
251251
if (prop == null) { // delegate
252252
args[i] = delegate;
253253
} else { // nope, injectable:

src/test/java/com/fasterxml/jackson/databind/creators/TestCreatorsWithIdentity.java

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,46 @@
99
import com.fasterxml.jackson.databind.BaseMapTest;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
1111

12-
/**
13-
* @author dharaburda
14-
*/
15-
public class TestCreatorsWithIdentity extends BaseMapTest {
16-
17-
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope=Parent.class)
18-
public static class Parent {
19-
@JsonProperty("id")
20-
String id;
21-
22-
@JsonProperty
23-
String parentProp;
24-
25-
@JsonCreator
26-
public Parent(@JsonProperty("parentProp") String parentProp) {
27-
this.parentProp = parentProp;
28-
}
29-
}
30-
31-
32-
public static class Child {
33-
@JsonProperty
34-
Parent parent;
35-
36-
@JsonProperty
37-
String childProp;
38-
39-
@JsonCreator
40-
public Child(@JsonProperty("parent") Parent parent, @JsonProperty("childProp") String childProp) {
41-
this.parent = parent;
42-
this.childProp = childProp;
43-
}
44-
}
45-
46-
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
47-
48-
public void test() throws IOException {
49-
String parentStr = "{\"id\" : \"1\", \"parentProp\" : \"parent\"}";
50-
String childStr = "{\"childProp\" : \"child\", \"parent\" : " + parentStr + "}";
51-
Parent parent = JSON_MAPPER.readValue(parentStr, Parent.class);
52-
Child child = JSON_MAPPER.readValue(childStr, Child.class);
53-
}
54-
12+
public class TestCreatorsWithIdentity extends BaseMapTest
13+
{
14+
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope=Parent.class)
15+
public static class Parent {
16+
@JsonProperty("id")
17+
String id;
18+
19+
@JsonProperty
20+
String parentProp;
21+
22+
@JsonCreator
23+
public Parent(@JsonProperty("parentProp") String parentProp) {
24+
this.parentProp = parentProp;
25+
}
26+
}
27+
28+
29+
public static class Child {
30+
@JsonProperty
31+
Parent parent;
32+
33+
@JsonProperty
34+
String childProp;
35+
36+
@JsonCreator
37+
public Child(@JsonProperty("parent") Parent parent, @JsonProperty("childProp") String childProp) {
38+
this.parent = parent;
39+
this.childProp = childProp;
40+
}
41+
}
42+
43+
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
44+
45+
public void testSimple() throws IOException
46+
{
47+
String parentStr = "{\"id\" : \"1\", \"parentProp\" : \"parent\"}";
48+
String childStr = "{\"childProp\" : \"child\", \"parent\" : " + parentStr + "}";
49+
Parent parent = JSON_MAPPER.readValue(parentStr, Parent.class);
50+
assertNotNull(parent);
51+
Child child = JSON_MAPPER.readValue(childStr, Child.class);
52+
assertNotNull(child);
53+
}
5554
}

0 commit comments

Comments
 (0)