Skip to content

Commit 1c63c80

Browse files
authored
Merge pull request #263 from FasterXML/tatu/3.0/databind-3561-post-merge-fix
Fix to pass DeserializationContext along with Afterburner set calls
2 parents ad505d7 + 9fec102 commit 1c63c80

18 files changed

+93
-77
lines changed

afterburner/src/main/java/tools/jackson/module/afterburner/deser/BeanPropertyMutator.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tools.jackson.module.afterburner.deser;
22

3+
import tools.jackson.databind.DeserializationContext;
4+
35
/**
46
* Abstract class that defines interface for implementations
57
* that can be used proxy-like to change values of properties,
@@ -31,34 +33,34 @@ public BeanPropertyMutator() { }
3133
// are non-trivial, and Afterburner may be deprecated with 3.0 anyway
3234
// so for now we just pass `null`
3335

34-
public void intSetter(Object bean, int propertyIndex, int value) {
36+
public void intSetter(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
3537
throw new UnsupportedOperationException("No intSetters defined");
3638
}
37-
public void longSetter(Object bean, int propertyIndex, long value){
39+
public void longSetter(DeserializationContext ctxt, Object bean, int propertyIndex, long value){
3840
throw new UnsupportedOperationException("No longSetters defined");
3941
}
40-
public void booleanSetter(Object bean, int propertyIndex, boolean value) {
42+
public void booleanSetter(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
4143
throw new UnsupportedOperationException("No booleanSetters defined");
4244
}
43-
public void stringSetter(Object bean, int propertyIndex, String value) {
45+
public void stringSetter(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
4446
throw new UnsupportedOperationException("No stringSetters defined");
4547
}
46-
public void objectSetter(Object bean, int propertyIndex, Object value) {
48+
public void objectSetter(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
4749
throw new UnsupportedOperationException("No objectSetters defined");
4850
}
49-
public void intField(Object bean, int propertyIndex, int value) {
51+
public void intField(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
5052
throw new UnsupportedOperationException("No intFields defined");
5153
}
52-
public void longField(Object bean, int propertyIndex, long value) {
54+
public void longField(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
5355
throw new UnsupportedOperationException("No longFields defined");
5456
}
55-
public void booleanField(Object bean, int propertyIndex, boolean value) {
57+
public void booleanField(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
5658
throw new UnsupportedOperationException("No booleanFields defined");
5759
}
58-
public void stringField(Object bean, int propertyIndex, String value) {
60+
public void stringField(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
5961
throw new UnsupportedOperationException("No stringFields defined");
6062
}
61-
public void objectField(Object bean, int propertyIndex, Object value) {
63+
public void objectField(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
6264
throw new UnsupportedOperationException("No objectFields defined");
6365
}
6466
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tools.jackson.module.afterburner.deser;
22

3+
import tools.jackson.databind.DeserializationContext;
34
import tools.jackson.databind.deser.SettableBeanProperty;
45

56
/**
@@ -19,44 +20,44 @@ public DelegatingPropertyMutator(SettableBeanProperty prop) {
1920
}
2021

2122
@Override
22-
public void intSetter(Object bean, int propertyIndex, int value) {
23-
_fallback.set(null, bean, value);
23+
public void intSetter(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
24+
_fallback.set(ctxt, bean, value);
2425
}
2526
@Override
26-
public void longSetter(Object bean, int propertyIndex, long value) {
27-
_fallback.set(null, bean, value);
27+
public void longSetter(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
28+
_fallback.set(ctxt, bean, value);
2829
}
2930
@Override
30-
public void booleanSetter(Object bean, int propertyIndex, boolean value) {
31-
_fallback.set(null, bean, value);
31+
public void booleanSetter(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
32+
_fallback.set(ctxt, bean, value);
3233
}
3334
@Override
34-
public void stringSetter(Object bean, int propertyIndex, String value) {
35-
_fallback.set(null, bean, value);
35+
public void stringSetter(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
36+
_fallback.set(ctxt, bean, value);
3637
}
3738
@Override
38-
public void objectSetter(Object bean, int propertyIndex, Object value) {
39-
_fallback.set(null, bean, value);
39+
public void objectSetter(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
40+
_fallback.set(ctxt, bean, value);
4041
}
4142

4243
@Override
43-
public void intField(Object bean, int propertyIndex, int value) {
44-
_fallback.set(null, bean, value);
44+
public void intField(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
45+
_fallback.set(ctxt, bean, value);
4546
}
4647
@Override
47-
public void longField(Object bean, int propertyIndex, long value) {
48-
_fallback.set(null, bean, value);
48+
public void longField(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
49+
_fallback.set(ctxt, bean, value);
4950
}
5051
@Override
51-
public void booleanField(Object bean, int propertyIndex, boolean value) {
52-
_fallback.set(null, bean, value);
52+
public void booleanField(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
53+
_fallback.set(ctxt, bean, value);
5354
}
5455
@Override
55-
public void stringField(Object bean, int propertyIndex, String value) {
56-
_fallback.set(null, bean, value);
56+
public void stringField(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
57+
_fallback.set(ctxt, bean, value);
5758
}
5859
@Override
59-
public void objectField(Object bean, int propertyIndex, Object value) {
60-
_fallback.set(null, bean, value);
60+
public void objectField(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
61+
_fallback.set(ctxt, bean, value);
6162
}
6263
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/PropertyMutatorCollector.java

+16-12
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public Class<?> generateMutatorClass(MyClassLoader classLoader, ClassName baseNa
190190

191191
/**
192192
* Implementation specific to {@link PropertyMutatorCollector}
193-
* We now that there are three arguments to the methods created in this case
193+
* We now that there are four arguments to the methods created in this case
194194
*/
195195
private static class LocalVarIndexCalculator implements AbstractPropertyStackManipulation.LocalVarIndexCalculator {
196196

@@ -211,19 +211,19 @@ public static LocalVarIndexCalculator of(MethodVariableAccess beanValueAccess) {
211211
return result;
212212
}
213213

214-
//we have 3 arguments (plus arg 0 which is 'this'), so 4 is the position of the first unless it's a long
214+
//we have 4 arguments (plus arg 0 which is 'this'), so 5 is the position of the first unless it's a long
215215
//this would look a lot nicer if MethodVariableAccess.stackSize were public...
216216
@Override
217217
public int calculate() {
218-
return 3 + (beanValueAccess == MethodVariableAccess.LONG ? 2 : 1);
218+
return 4 + (beanValueAccess == MethodVariableAccess.LONG ? 2 : 1);
219219
}
220220
}
221221

222222
private static class CreateLocalVarStackManipulation extends AbstractCreateLocalVarStackManipulation {
223223

224224
CreateLocalVarStackManipulation(TypeDescription beanClassDescription,
225-
MethodVariableAccess beanValueAccess) {
226-
super(beanClassDescription, PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess));
225+
MethodVariableAccess beanValueAccess) {
226+
super(beanClassDescription, PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess), true);
227227
}
228228

229229
private static Map<Integer, CreateLocalVarStackManipulation> cache
@@ -259,7 +259,7 @@ private abstract static class AbstractSinglePropStackManipulation<T extends Opti
259259
AbstractSinglePropStackManipulation(TypeDescription beanClassDescription,
260260
T prop,
261261
MethodVariableAccess beanValueAccess) {
262-
super(PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess));
262+
super(PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess), true);
263263
this.beanValueAccess = beanValueAccess;
264264
this.beanClassDescription = beanClassDescription;
265265
this.prop = prop;
@@ -300,10 +300,10 @@ private StackManipulation loadBeanValueArg() {
300300
}
301301

302302
/**
303-
* we know that all methods of created in {@link PropertyMutatorCollector} contain the bean value as the 3rd arg
303+
* we know that all methods of created in {@link PropertyMutatorCollector} contain the bean value as the 4th arg
304304
*/
305305
private int beanValueArgIndex() {
306-
return 3;
306+
return 4;
307307
}
308308
}
309309

@@ -399,7 +399,8 @@ protected StackManipulation usingSwitch() {
399399
return new UsingSwitchStackManipulation<T>(
400400
LocalVarIndexCalculator.of(beanValueAccess),
401401
props,
402-
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
402+
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
403+
true
403404
);
404405
}
405406

@@ -414,7 +415,8 @@ protected StackManipulation usingIf() {
414415
return new UsingIfStackManipulation<T>(
415416
LocalVarIndexCalculator.of(beanValueAccess),
416417
props,
417-
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
418+
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
419+
true
418420
);
419421
}
420422

@@ -612,7 +614,8 @@ protected StackManipulation usingSwitch() {
612614
return new UsingSwitchStackManipulation<T>(
613615
LocalVarIndexCalculator.of(beanValueAccess),
614616
props,
615-
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
617+
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
618+
true
616619
);
617620
}
618621

@@ -622,7 +625,8 @@ protected StackManipulation usingIf() {
622625
return new UsingIfStackManipulation<T>(
623626
LocalVarIndexCalculator.of(beanValueAccess),
624627
props,
625-
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
628+
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
629+
true
626630
);
627631
}
628632

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableBooleanFieldProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4646
return;
4747
}
4848
try {
49-
_propertyMutator.booleanField(bean, _optimizedIndex, b);
49+
_propertyMutator.booleanField(ctxt, bean, _optimizedIndex, b);
5050
} catch (Throwable e) {
5151
_reportProblem(ctxt, bean, b, e);
5252
}
@@ -57,7 +57,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value) {
5757
// not optimal (due to boxing), but better than using reflection:
5858
final boolean b = ((Boolean) value).booleanValue();
5959
try {
60-
_propertyMutator.booleanField(bean, _optimizedIndex, b);
60+
_propertyMutator.booleanField(ctxt, bean, _optimizedIndex, b);
6161
} catch (Throwable e) {
6262
_reportProblem(ctxt, bean, b, e);
6363
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableBooleanMethodProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4646
return;
4747
}
4848
try {
49-
_propertyMutator.booleanSetter(bean, _optimizedIndex, b);
49+
_propertyMutator.booleanSetter(ctxt, bean, _optimizedIndex, b);
5050
} catch (Throwable e) {
5151
_reportProblem(ctxt, bean, b, e);
5252
}
@@ -57,7 +57,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value) {
5757
// not optimal (due to boxing), but better than using reflection:
5858
final boolean b = ((Boolean) value).booleanValue();
5959
try {
60-
_propertyMutator.booleanSetter(bean, _optimizedIndex, b);
60+
_propertyMutator.booleanSetter(ctxt, bean, _optimizedIndex, b);
6161
} catch (Throwable e) {
6262
_reportProblem(ctxt, bean, b, e);
6363
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableIntFieldProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4141
}
4242
final int v = p.getIntValue();
4343
try {
44-
_propertyMutator.intField(bean, _optimizedIndex, v);
44+
_propertyMutator.intField(ctxt, bean, _optimizedIndex, v);
4545
} catch (Throwable e) {
4646
_reportProblem(ctxt, bean, v, e);
4747
}
@@ -64,7 +64,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6464
// not optimal (due to boxing), but better than using reflection:
6565
final int v = ((Number) value).intValue();
6666
try {
67-
_propertyMutator.intField(bean, _optimizedIndex, v);
67+
_propertyMutator.intField(ctxt, bean, _optimizedIndex, v);
6868
} catch (Throwable e) {
6969
_reportProblem(ctxt, bean, v, e);
7070
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableIntMethodProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4242
}
4343
final int v = p.getIntValue();
4444
try {
45-
_propertyMutator.intSetter(bean, _optimizedIndex, v);
45+
_propertyMutator.intSetter(ctxt, bean, _optimizedIndex, v);
4646
} catch (Throwable e) {
4747
_reportProblem(ctxt, bean, v, e);
4848
}
@@ -65,7 +65,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6565
// not optimal (due to boxing), but better than using reflection:
6666
int v = ((Number) value).intValue();
6767
try {
68-
_propertyMutator.intSetter(bean, _optimizedIndex, v);
68+
_propertyMutator.intSetter(ctxt, bean, _optimizedIndex, v);
6969
} catch (Throwable e) {
7070
_reportProblem(ctxt, bean, v, e);
7171
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableLongFieldProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4141
}
4242
final long v = p.getLongValue();
4343
try {
44-
_propertyMutator.longField(bean, _optimizedIndex, v);
44+
_propertyMutator.longField(ctxt, bean, _optimizedIndex, v);
4545
} catch (Throwable e) {
4646
_reportProblem(ctxt, bean, v, e);
4747
}
@@ -64,7 +64,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6464
// not optimal (due to boxing), but better than using reflection:
6565
final long v = ((Number) value).longValue();
6666
try {
67-
_propertyMutator.longField(bean, _optimizedIndex, v);
67+
_propertyMutator.longField(ctxt, bean, _optimizedIndex, v);
6868
} catch (Throwable e) {
6969
_reportProblem(ctxt, bean, v, e);
7070
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableLongMethodProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4242
}
4343
final long v = p.getLongValue();
4444
try {
45-
_propertyMutator.longSetter(bean, _optimizedIndex, v);
45+
_propertyMutator.longSetter(ctxt, bean, _optimizedIndex, v);
4646
} catch (Throwable e) {
4747
_reportProblem(ctxt, bean, v, e);
4848
}
@@ -65,7 +65,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6565
// not optimal (due to boxing), but better than using reflection:
6666
final long v = ((Number) value).longValue();
6767
try {
68-
_propertyMutator.longSetter(bean, _optimizedIndex, v);
68+
_propertyMutator.longSetter(ctxt, bean, _optimizedIndex, v);
6969
} catch (Throwable e) {
7070
_reportProblem(ctxt, bean, v, e);
7171
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableObjectFieldProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
5555
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
5656
}
5757
try {
58-
_propertyMutator.objectField(bean, _optimizedIndex, value);
58+
_propertyMutator.objectField(ctxt, bean, _optimizedIndex, value);
5959
} catch (Throwable e) {
6060
_reportProblem(ctxt, bean, value, e);
6161
}
@@ -91,7 +91,7 @@ public Object deserializeSetAndReturn(JsonParser p,
9191
public void set(DeserializationContext ctxt, Object bean, Object v)
9292
{
9393
try {
94-
_propertyMutator.objectField(bean, _optimizedIndex, v);
94+
_propertyMutator.objectField(ctxt, bean, _optimizedIndex, v);
9595
} catch (Throwable e) {
9696
_reportProblem(ctxt, bean, v, e);
9797
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableObjectMethodProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
5555
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
5656
}
5757
try {
58-
_propertyMutator.objectSetter(bean, _optimizedIndex, value);
58+
_propertyMutator.objectSetter(ctxt, bean, _optimizedIndex, value);
5959
} catch (Throwable e) {
6060
_reportProblem(ctxt, bean, value, e);
6161
}
@@ -91,7 +91,7 @@ public Object deserializeSetAndReturn(JsonParser p,
9191
public void set(DeserializationContext ctxt, Object bean, Object v)
9292
{
9393
try {
94-
_propertyMutator.objectSetter(bean, _optimizedIndex, v);
94+
_propertyMutator.objectSetter(ctxt, bean, _optimizedIndex, v);
9595
} catch (Throwable e) {
9696
_reportProblem(ctxt, bean, v, e);
9797
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableStringFieldProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4242
}
4343
final String text = p.getText();
4444
try {
45-
_propertyMutator.stringField(bean, _optimizedIndex, text);
45+
_propertyMutator.stringField(ctxt, bean, _optimizedIndex, text);
4646
} catch (Throwable e) {
4747
_reportProblem(ctxt, bean, text, e);
4848
}
@@ -63,7 +63,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6363
{
6464
final String text = (String) value;
6565
try {
66-
_propertyMutator.stringField(bean, _optimizedIndex, text);
66+
_propertyMutator.stringField(ctxt, bean, _optimizedIndex, text);
6767
} catch (Throwable e) {
6868
_reportProblem(ctxt, bean, text, e);
6969
}

afterburner/src/main/java/tools/jackson/module/afterburner/deser/SettableStringMethodProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
4242
}
4343
final String text = p.getText();
4444
try {
45-
_propertyMutator.stringSetter(bean, _optimizedIndex, text);
45+
_propertyMutator.stringSetter(ctxt, bean, _optimizedIndex, text);
4646
} catch (Throwable e) {
4747
_reportProblem(ctxt, bean, text, e);
4848
}
@@ -63,7 +63,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
6363
{
6464
final String text = (String) value;
6565
try {
66-
_propertyMutator.stringSetter(bean, _optimizedIndex, text);
66+
_propertyMutator.stringSetter(ctxt, bean, _optimizedIndex, text);
6767
} catch (Throwable e) {
6868
_reportProblem(ctxt, bean, text, e);
6969
}

0 commit comments

Comments
 (0)