Skip to content

Commit

Permalink
Merge pull request #263 from FasterXML/tatu/3.0/databind-3561-post-me…
Browse files Browse the repository at this point in the history
…rge-fix

Fix to pass DeserializationContext along with Afterburner set calls
  • Loading branch information
cowtowncoder authored Dec 7, 2024
2 parents ad505d7 + 9fec102 commit 1c63c80
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tools.jackson.module.afterburner.deser;

import tools.jackson.databind.DeserializationContext;

/**
* Abstract class that defines interface for implementations
* that can be used proxy-like to change values of properties,
Expand Down Expand Up @@ -31,34 +33,34 @@ public BeanPropertyMutator() { }
// are non-trivial, and Afterburner may be deprecated with 3.0 anyway
// so for now we just pass `null`

public void intSetter(Object bean, int propertyIndex, int value) {
public void intSetter(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
throw new UnsupportedOperationException("No intSetters defined");
}
public void longSetter(Object bean, int propertyIndex, long value){
public void longSetter(DeserializationContext ctxt, Object bean, int propertyIndex, long value){
throw new UnsupportedOperationException("No longSetters defined");
}
public void booleanSetter(Object bean, int propertyIndex, boolean value) {
public void booleanSetter(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
throw new UnsupportedOperationException("No booleanSetters defined");
}
public void stringSetter(Object bean, int propertyIndex, String value) {
public void stringSetter(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
throw new UnsupportedOperationException("No stringSetters defined");
}
public void objectSetter(Object bean, int propertyIndex, Object value) {
public void objectSetter(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
throw new UnsupportedOperationException("No objectSetters defined");
}
public void intField(Object bean, int propertyIndex, int value) {
public void intField(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
throw new UnsupportedOperationException("No intFields defined");
}
public void longField(Object bean, int propertyIndex, long value) {
public void longField(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
throw new UnsupportedOperationException("No longFields defined");
}
public void booleanField(Object bean, int propertyIndex, boolean value) {
public void booleanField(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
throw new UnsupportedOperationException("No booleanFields defined");
}
public void stringField(Object bean, int propertyIndex, String value) {
public void stringField(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
throw new UnsupportedOperationException("No stringFields defined");
}
public void objectField(Object bean, int propertyIndex, Object value) {
public void objectField(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
throw new UnsupportedOperationException("No objectFields defined");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.jackson.module.afterburner.deser;

import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.deser.SettableBeanProperty;

/**
Expand All @@ -19,44 +20,44 @@ public DelegatingPropertyMutator(SettableBeanProperty prop) {
}

@Override
public void intSetter(Object bean, int propertyIndex, int value) {
_fallback.set(null, bean, value);
public void intSetter(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void longSetter(Object bean, int propertyIndex, long value) {
_fallback.set(null, bean, value);
public void longSetter(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void booleanSetter(Object bean, int propertyIndex, boolean value) {
_fallback.set(null, bean, value);
public void booleanSetter(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void stringSetter(Object bean, int propertyIndex, String value) {
_fallback.set(null, bean, value);
public void stringSetter(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void objectSetter(Object bean, int propertyIndex, Object value) {
_fallback.set(null, bean, value);
public void objectSetter(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
_fallback.set(ctxt, bean, value);
}

@Override
public void intField(Object bean, int propertyIndex, int value) {
_fallback.set(null, bean, value);
public void intField(DeserializationContext ctxt, Object bean, int propertyIndex, int value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void longField(Object bean, int propertyIndex, long value) {
_fallback.set(null, bean, value);
public void longField(DeserializationContext ctxt, Object bean, int propertyIndex, long value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void booleanField(Object bean, int propertyIndex, boolean value) {
_fallback.set(null, bean, value);
public void booleanField(DeserializationContext ctxt, Object bean, int propertyIndex, boolean value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void stringField(Object bean, int propertyIndex, String value) {
_fallback.set(null, bean, value);
public void stringField(DeserializationContext ctxt, Object bean, int propertyIndex, String value) {
_fallback.set(ctxt, bean, value);
}
@Override
public void objectField(Object bean, int propertyIndex, Object value) {
_fallback.set(null, bean, value);
public void objectField(DeserializationContext ctxt, Object bean, int propertyIndex, Object value) {
_fallback.set(ctxt, bean, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Class<?> generateMutatorClass(MyClassLoader classLoader, ClassName baseNa

/**
* Implementation specific to {@link PropertyMutatorCollector}
* We now that there are three arguments to the methods created in this case
* We now that there are four arguments to the methods created in this case
*/
private static class LocalVarIndexCalculator implements AbstractPropertyStackManipulation.LocalVarIndexCalculator {

Expand All @@ -211,19 +211,19 @@ public static LocalVarIndexCalculator of(MethodVariableAccess beanValueAccess) {
return result;
}

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

private static class CreateLocalVarStackManipulation extends AbstractCreateLocalVarStackManipulation {

CreateLocalVarStackManipulation(TypeDescription beanClassDescription,
MethodVariableAccess beanValueAccess) {
super(beanClassDescription, PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess));
MethodVariableAccess beanValueAccess) {
super(beanClassDescription, PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess), true);
}

private static Map<Integer, CreateLocalVarStackManipulation> cache
Expand Down Expand Up @@ -259,7 +259,7 @@ private abstract static class AbstractSinglePropStackManipulation<T extends Opti
AbstractSinglePropStackManipulation(TypeDescription beanClassDescription,
T prop,
MethodVariableAccess beanValueAccess) {
super(PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess));
super(PropertyMutatorCollector.LocalVarIndexCalculator.of(beanValueAccess), true);
this.beanValueAccess = beanValueAccess;
this.beanClassDescription = beanClassDescription;
this.prop = prop;
Expand Down Expand Up @@ -300,10 +300,10 @@ private StackManipulation loadBeanValueArg() {
}

/**
* we know that all methods of created in {@link PropertyMutatorCollector} contain the bean value as the 3rd arg
* we know that all methods of created in {@link PropertyMutatorCollector} contain the bean value as the 4th arg
*/
private int beanValueArgIndex() {
return 3;
return 4;
}
}

Expand Down Expand Up @@ -399,7 +399,8 @@ protected StackManipulation usingSwitch() {
return new UsingSwitchStackManipulation<T>(
LocalVarIndexCalculator.of(beanValueAccess),
props,
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
true
);
}

Expand All @@ -414,7 +415,8 @@ protected StackManipulation usingIf() {
return new UsingIfStackManipulation<T>(
LocalVarIndexCalculator.of(beanValueAccess),
props,
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
SingleFieldStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
true
);
}

Expand Down Expand Up @@ -612,7 +614,8 @@ protected StackManipulation usingSwitch() {
return new UsingSwitchStackManipulation<T>(
LocalVarIndexCalculator.of(beanValueAccess),
props,
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
true
);
}

Expand All @@ -622,7 +625,8 @@ protected StackManipulation usingIf() {
return new UsingIfStackManipulation<T>(
LocalVarIndexCalculator.of(beanValueAccess),
props,
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess)
SingleMethodStackManipulationSupplier.<T>of(beanClassDescription, beanValueAccess),
true
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
return;
}
try {
_propertyMutator.booleanField(bean, _optimizedIndex, b);
_propertyMutator.booleanField(ctxt, bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(ctxt, bean, b, e);
}
Expand All @@ -57,7 +57,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value) {
// not optimal (due to boxing), but better than using reflection:
final boolean b = ((Boolean) value).booleanValue();
try {
_propertyMutator.booleanField(bean, _optimizedIndex, b);
_propertyMutator.booleanField(ctxt, bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(ctxt, bean, b, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
return;
}
try {
_propertyMutator.booleanSetter(bean, _optimizedIndex, b);
_propertyMutator.booleanSetter(ctxt, bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(ctxt, bean, b, e);
}
Expand All @@ -57,7 +57,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value) {
// not optimal (due to boxing), but better than using reflection:
final boolean b = ((Boolean) value).booleanValue();
try {
_propertyMutator.booleanSetter(bean, _optimizedIndex, b);
_propertyMutator.booleanSetter(ctxt, bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(ctxt, bean, b, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final int v = p.getIntValue();
try {
_propertyMutator.intField(bean, _optimizedIndex, v);
_propertyMutator.intField(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand All @@ -64,7 +64,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
// not optimal (due to boxing), but better than using reflection:
final int v = ((Number) value).intValue();
try {
_propertyMutator.intField(bean, _optimizedIndex, v);
_propertyMutator.intField(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final int v = p.getIntValue();
try {
_propertyMutator.intSetter(bean, _optimizedIndex, v);
_propertyMutator.intSetter(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand All @@ -65,7 +65,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
// not optimal (due to boxing), but better than using reflection:
int v = ((Number) value).intValue();
try {
_propertyMutator.intSetter(bean, _optimizedIndex, v);
_propertyMutator.intSetter(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final long v = p.getLongValue();
try {
_propertyMutator.longField(bean, _optimizedIndex, v);
_propertyMutator.longField(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand All @@ -64,7 +64,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
// not optimal (due to boxing), but better than using reflection:
final long v = ((Number) value).longValue();
try {
_propertyMutator.longField(bean, _optimizedIndex, v);
_propertyMutator.longField(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final long v = p.getLongValue();
try {
_propertyMutator.longSetter(bean, _optimizedIndex, v);
_propertyMutator.longSetter(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand All @@ -65,7 +65,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
// not optimal (due to boxing), but better than using reflection:
final long v = ((Number) value).longValue();
try {
_propertyMutator.longSetter(bean, _optimizedIndex, v);
_propertyMutator.longSetter(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
}
try {
_propertyMutator.objectField(bean, _optimizedIndex, value);
_propertyMutator.objectField(ctxt, bean, _optimizedIndex, value);
} catch (Throwable e) {
_reportProblem(ctxt, bean, value, e);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public Object deserializeSetAndReturn(JsonParser p,
public void set(DeserializationContext ctxt, Object bean, Object v)
{
try {
_propertyMutator.objectField(bean, _optimizedIndex, v);
_propertyMutator.objectField(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
}
try {
_propertyMutator.objectSetter(bean, _optimizedIndex, value);
_propertyMutator.objectSetter(ctxt, bean, _optimizedIndex, value);
} catch (Throwable e) {
_reportProblem(ctxt, bean, value, e);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public Object deserializeSetAndReturn(JsonParser p,
public void set(DeserializationContext ctxt, Object bean, Object v)
{
try {
_propertyMutator.objectSetter(bean, _optimizedIndex, v);
_propertyMutator.objectSetter(ctxt, bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(ctxt, bean, v, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final String text = p.getText();
try {
_propertyMutator.stringField(bean, _optimizedIndex, text);
_propertyMutator.stringField(ctxt, bean, _optimizedIndex, text);
} catch (Throwable e) {
_reportProblem(ctxt, bean, text, e);
}
Expand All @@ -63,7 +63,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
{
final String text = (String) value;
try {
_propertyMutator.stringField(bean, _optimizedIndex, text);
_propertyMutator.stringField(ctxt, bean, _optimizedIndex, text);
} catch (Throwable e) {
_reportProblem(ctxt, bean, text, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
}
final String text = p.getText();
try {
_propertyMutator.stringSetter(bean, _optimizedIndex, text);
_propertyMutator.stringSetter(ctxt, bean, _optimizedIndex, text);
} catch (Throwable e) {
_reportProblem(ctxt, bean, text, e);
}
Expand All @@ -63,7 +63,7 @@ public void set(DeserializationContext ctxt, Object bean, Object value)
{
final String text = (String) value;
try {
_propertyMutator.stringSetter(bean, _optimizedIndex, text);
_propertyMutator.stringSetter(ctxt, bean, _optimizedIndex, text);
} catch (Throwable e) {
_reportProblem(ctxt, bean, text, e);
}
Expand Down
Loading

0 comments on commit 1c63c80

Please sign in to comment.