Skip to content

Commit ec504db

Browse files
committed
Refactoring to use new SettableBeanProperty.Delegating to simplify OptimizedSettableBeanProperty
1 parent ebc4e40 commit ec504db

12 files changed

+60
-256
lines changed

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/OptimizedSettableBeanProperty.java

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
package com.fasterxml.jackson.module.afterburner.deser;
22

33
import java.io.IOException;
4-
import java.lang.annotation.Annotation;
54

65
import com.fasterxml.jackson.core.*;
76
import com.fasterxml.jackson.core.JsonParser.NumberType;
87
import com.fasterxml.jackson.core.io.NumberInput;
98
import com.fasterxml.jackson.databind.*;
109
import com.fasterxml.jackson.databind.deser.*;
11-
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
1210
import com.fasterxml.jackson.databind.util.ClassUtil;
1311

1412
/**
1513
* Base class for concrete type-specific {@link SettableBeanProperty}
1614
* implementations.
1715
*/
1816
abstract class OptimizedSettableBeanProperty<T extends OptimizedSettableBeanProperty<T>>
19-
extends SettableBeanProperty
17+
extends SettableBeanProperty.Delegating
2018
{
21-
private static final long serialVersionUID = 1L; // since 2.5
22-
23-
/**
24-
* We will need to keep the original instance handy as
25-
* some calls are best just delegated
26-
*/
27-
protected final SettableBeanProperty _originalSettable;
19+
private static final long serialVersionUID = 1L;
2820

2921
protected final BeanPropertyMutator _propertyMutator;
3022
protected final int _optimizedIndex;
@@ -35,59 +27,35 @@ abstract class OptimizedSettableBeanProperty<T extends OptimizedSettableBeanProp
3527
/**********************************************************************
3628
*/
3729

38-
public OptimizedSettableBeanProperty(SettableBeanProperty src,
30+
protected OptimizedSettableBeanProperty(SettableBeanProperty src,
3931
BeanPropertyMutator mutator, int index)
4032
{
4133
super(src);
42-
_originalSettable = src;
4334
_propertyMutator = mutator;
4435
_optimizedIndex = index;
4536
}
4637

47-
protected OptimizedSettableBeanProperty(OptimizedSettableBeanProperty<T> src,
48-
JsonDeserializer<?> deser)
49-
{
50-
super(src, deser);
51-
_originalSettable = src._originalSettable.withValueDeserializer(deser);
52-
_propertyMutator = src._propertyMutator;
53-
_optimizedIndex = src._optimizedIndex;
54-
}
38+
// Base impl of `withName()` fine as-is:
39+
// public SettableBeanProperty withName(PropertyName name);
5540

56-
protected OptimizedSettableBeanProperty(OptimizedSettableBeanProperty<T> src,
57-
PropertyName name)
58-
{
59-
super(src, name);
60-
_originalSettable = src._originalSettable.withName(name);
61-
_propertyMutator = src._propertyMutator;
62-
_optimizedIndex = src._optimizedIndex;
41+
// But value deserializer handling needs some more care
42+
@Override
43+
public final SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
44+
SettableBeanProperty newDelegate = delegate.withValueDeserializer(deser);
45+
if (newDelegate == delegate) {
46+
return this;
47+
}
48+
if (!_isDefaultDeserializer(deser)) {
49+
return newDelegate;
50+
}
51+
return withDelegate(newDelegate);
6352
}
6453

6554
@Override
66-
public abstract SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser);
55+
protected abstract SettableBeanProperty withDelegate(SettableBeanProperty d);
6756

6857
public abstract SettableBeanProperty withMutator(BeanPropertyMutator mut);
6958

70-
@Override // added in SettableBeanProperty in 2.8.3
71-
public void fixAccess(DeserializationConfig config) {
72-
_originalSettable.fixAccess(config);
73-
}
74-
75-
/*
76-
/**********************************************************************
77-
/* Overridden getters
78-
/**********************************************************************
79-
*/
80-
81-
@Override
82-
public <A extends Annotation> A getAnnotation(Class<A> ann) {
83-
return _originalSettable.getAnnotation(ann);
84-
}
85-
86-
@Override
87-
public AnnotatedMember getMember() {
88-
return _originalSettable.getMember();
89-
}
90-
9159
/*
9260
/**********************************************************************
9361
/* Deserialization, regular
@@ -124,7 +92,7 @@ public abstract Object deserializeSetAndReturn(JsonParser jp,
12492

12593
@Override
12694
public Object setAndReturn(Object instance, Object value) throws IOException {
127-
return _originalSettable.setAndReturn(instance, value);
95+
return delegate.setAndReturn(instance, value);
12896
}
12997

13098
/*
@@ -134,7 +102,7 @@ public Object setAndReturn(Object instance, Object value) throws IOException {
134102
*/
135103

136104
public SettableBeanProperty getOriginalProperty() {
137-
return _originalSettable;
105+
return delegate;
138106
}
139107

140108
public int getOptimizedIndex() {

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableBooleanFieldProperty.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,14 @@ public SettableBooleanFieldProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableBooleanFieldProperty(SettableBooleanFieldProperty src,
21-
JsonDeserializer<?> deser)
22-
{
23-
super(src, deser);
24-
}
25-
26-
public SettableBooleanFieldProperty(SettableBooleanFieldProperty src, PropertyName name) {
27-
super(src, name);
28-
}
29-
3020
@Override
31-
public SettableBeanProperty withName(PropertyName name) {
32-
return new SettableBooleanFieldProperty(this, name);
33-
}
34-
35-
@Override
36-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
37-
if (!_isDefaultDeserializer(deser)) {
38-
return _originalSettable.withValueDeserializer(deser);
39-
}
40-
return new SettableBooleanFieldProperty(this, deser);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableBooleanFieldProperty(del, _propertyMutator, _optimizedIndex);
4123
}
4224

4325
@Override
4426
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
45-
return new SettableBooleanFieldProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableBooleanFieldProperty(delegate, mut, _optimizedIndex);
4628
}
4729

4830
/*

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableBooleanMethodProperty.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,14 @@ public SettableBooleanMethodProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableBooleanMethodProperty(SettableBooleanMethodProperty src, JsonDeserializer<?> deser) {
21-
super(src, deser);
22-
}
23-
24-
public SettableBooleanMethodProperty(SettableBooleanMethodProperty src, PropertyName name) {
25-
super(src, name);
26-
}
27-
28-
@Override
29-
public SettableBeanProperty withName(PropertyName name) {
30-
return new SettableBooleanMethodProperty(this, name);
31-
}
32-
3320
@Override
34-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
35-
if (!_isDefaultDeserializer(deser)) {
36-
return _originalSettable.withValueDeserializer(deser);
37-
}
38-
return new SettableBooleanMethodProperty(this, deser);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableBooleanMethodProperty(del, _propertyMutator, _optimizedIndex);
3923
}
40-
24+
4125
@Override
4226
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
43-
return new SettableBooleanMethodProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableBooleanMethodProperty(delegate, mut, _optimizedIndex);
4428
}
4529

4630
/*

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableIntFieldProperty.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,14 @@ public SettableIntFieldProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableIntFieldProperty(SettableIntFieldProperty src,
21-
JsonDeserializer<?> deser)
22-
{
23-
super(src, deser);
24-
}
25-
26-
public SettableIntFieldProperty(SettableIntFieldProperty src, PropertyName name) {
27-
super(src, name);
28-
}
29-
30-
@Override
31-
public SettableBeanProperty withName(PropertyName name) {
32-
return new SettableIntFieldProperty(this, name);
33-
}
34-
3520
@Override
36-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
37-
if (!_isDefaultDeserializer(deser)) {
38-
return _originalSettable.withValueDeserializer(deser);
39-
}
40-
return new SettableIntFieldProperty(this, deser);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableIntFieldProperty(del, _propertyMutator, _optimizedIndex);
4123
}
4224

4325
@Override
4426
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
45-
return new SettableIntFieldProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableIntFieldProperty(delegate, mut, _optimizedIndex);
4628
}
4729

4830
/*

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableIntMethodProperty.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,22 @@ public SettableIntMethodProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableIntMethodProperty(SettableIntMethodProperty src, JsonDeserializer<?> deser) {
21-
super(src, deser);
22-
}
23-
24-
public SettableIntMethodProperty(SettableIntMethodProperty src, PropertyName name) {
25-
super(src, name);
26-
}
27-
2820
@Override
29-
public SettableBeanProperty withName(PropertyName name) {
30-
return new SettableIntMethodProperty(this, name);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableIntMethodProperty(del, _propertyMutator, _optimizedIndex);
3123
}
32-
33-
@Override
34-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
35-
if (!_isDefaultDeserializer(deser)) {
36-
return _originalSettable.withValueDeserializer(deser);
37-
}
38-
return new SettableIntMethodProperty(this, deser);
39-
}
40-
24+
4125
@Override
4226
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
43-
return new SettableIntMethodProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableIntMethodProperty(delegate, mut, _optimizedIndex);
4428
}
4529

4630
/*
4731
/**********************************************************************
4832
/* Deserialization
4933
/**********************************************************************
5034
*/
51-
35+
5236
@Override
5337
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
5438
Object bean) throws IOException

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableLongFieldProperty.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,22 @@ public SettableLongFieldProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableLongFieldProperty(SettableLongFieldProperty src, JsonDeserializer<?> deser) {
21-
super(src, deser);
22-
}
23-
24-
public SettableLongFieldProperty(SettableLongFieldProperty src, PropertyName name) {
25-
super(src, name);
26-
}
27-
2820
@Override
29-
public SettableBeanProperty withName(PropertyName name) {
30-
return new SettableLongFieldProperty(this, name);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableLongFieldProperty(del, _propertyMutator, _optimizedIndex);
3123
}
32-
33-
@Override
34-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
35-
if (!_isDefaultDeserializer(deser)) {
36-
return _originalSettable.withValueDeserializer(deser);
37-
}
38-
return new SettableLongFieldProperty(this, deser);
39-
}
40-
24+
4125
@Override
4226
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
43-
return new SettableLongFieldProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableLongFieldProperty(delegate, mut, _optimizedIndex);
4428
}
4529

4630
/*
4731
/**********************************************************************
4832
/* Deserialization
4933
/**********************************************************************
5034
*/
51-
35+
5236
@Override
5337
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
5438
Object bean) throws IOException

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableLongMethodProperty.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,14 @@ public SettableLongMethodProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableLongMethodProperty(SettableLongMethodProperty src, JsonDeserializer<?> deser) {
21-
super(src, deser);
22-
}
23-
24-
public SettableLongMethodProperty(SettableLongMethodProperty src, PropertyName name) {
25-
super(src, name);
26-
}
27-
2820
@Override
29-
public SettableBeanProperty withName(PropertyName name) {
30-
return new SettableLongMethodProperty(this, name);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableLongMethodProperty(del, _propertyMutator, _optimizedIndex);
3123
}
32-
33-
@Override
34-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
35-
if (!_isDefaultDeserializer(deser)) {
36-
return _originalSettable.withValueDeserializer(deser);
37-
}
38-
return new SettableLongMethodProperty(this, deser);
39-
}
40-
24+
4125
@Override
4226
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
43-
return new SettableLongMethodProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableLongMethodProperty(delegate, mut, _optimizedIndex);
4428
}
4529

4630
/*

afterburner/src/main/java/com/fasterxml/jackson/module/afterburner/deser/SettableObjectFieldProperty.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,22 @@ public SettableObjectFieldProperty(SettableBeanProperty src,
1717
super(src, mutator, index);
1818
}
1919

20-
public SettableObjectFieldProperty(SettableObjectFieldProperty src, JsonDeserializer<?> deser) {
21-
super(src, deser);
22-
}
23-
24-
public SettableObjectFieldProperty(SettableObjectFieldProperty src, PropertyName name) {
25-
super(src, name);
26-
}
27-
2820
@Override
29-
public SettableBeanProperty withName(PropertyName name) {
30-
return new SettableObjectFieldProperty(this, name);
31-
}
32-
33-
@Override
34-
public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
35-
if (!_isDefaultDeserializer(deser)) {
36-
return _originalSettable.withValueDeserializer(deser);
37-
}
38-
return new SettableObjectFieldProperty(this, deser);
21+
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
22+
return new SettableObjectFieldProperty(del, _propertyMutator, _optimizedIndex);
3923
}
4024

4125
@Override
4226
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
43-
return new SettableObjectFieldProperty(_originalSettable, mut, _optimizedIndex);
27+
return new SettableObjectFieldProperty(delegate, mut, _optimizedIndex);
4428
}
4529

4630
/*
4731
/**********************************************************************
4832
/* Deserialization
4933
/**********************************************************************
5034
*/
51-
35+
5236
@Override
5337
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
5438
Object bean) throws IOException

0 commit comments

Comments
 (0)