Skip to content

Commit

Permalink
Implement version 2
Browse files Browse the repository at this point in the history
Add quick check before iteration start
  • Loading branch information
JooHyukKim committed Feb 10, 2024
1 parent 47ac3f7 commit 8612433
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ protected void _reportUnwrappedCreatorProperty(DeserializationContext ctxt,
* a logical property passed via Creator (constructor or static
* factory method)
*
* @since 2.18
* @since 2.19
*/
protected SettableBeanProperty constructCreatorProperty(DeserializationContext ctxt,
BeanDescription beanDesc, PropertyName name, int index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
throws IOException
{
final PropertyBasedCreator creator = _propertyBasedCreator;
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader);
PropertyValueBuffer buffer = (_anySetter != null)
? creator.startBuildingWithAnySetter(p, ctxt, _objectIdReader, _anySetter)
: creator.startBuilding(p, ctxt, _objectIdReader);
TokenBuffer unknown = null;
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;

Expand Down Expand Up @@ -495,9 +497,10 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
continue;
}
// "any property"?

if (_anySetter != null) {
try {
buffer.bufferMapProperty(propName, _anySetter.deserialize(p, ctxt));
buffer.bufferWithAnySetter(ctxt, p, creator, propName);
} catch (Exception e) {
wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt);
}
Expand All @@ -523,11 +526,7 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
// We hit END_OBJECT, so:
Object bean;
try {
if (_anySetter != null) {
bean = creator.buildWithAnySetter(ctxt, buffer, _anySetter);
} else {
bean = creator.build(ctxt, buffer);
}
bean = creator.build(ctxt, buffer);
} catch (Exception e) {
return wrapInstantiationProblem(e, ctxt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public class CreatorProperty
/**
* Marker flag to indicate that current property is used to handle "any setter" via `@JsonAnySetter`.
*
* @since 2.18
* @since 2.19
*/
protected final boolean _isAnySetterProp;

/**
* @since 2.18
* @since 2.19
*/
protected CreatorProperty(PropertyName name, JavaType type, PropertyName wrapperName,
TypeDeserializer typeDeser,
Expand Down Expand Up @@ -148,7 +148,7 @@ public CreatorProperty(PropertyName name, JavaType type, PropertyName wrapperNam
* @param index Index of this property within creator invocation
* @param isAnySetter Marker flag to indicate that current property is used to handle "any setter" via `@JsonAnySetter`.
*
* @since 2.18
* @since 2.19
*/
public static CreatorProperty construct(PropertyName name, JavaType type, PropertyName wrapperName,
TypeDeserializer typeDeser,
Expand Down Expand Up @@ -364,7 +364,7 @@ public boolean isInjectionOnly() {
// public boolean isInjectionOnly() { return false; }

/**
* @since 2.18
* @since 2.19
*/
public boolean isAnySetterProp() {
return _isAnySetterProp;
Expand Down Expand Up @@ -406,7 +406,7 @@ private void _reportMissingSetter(JsonParser p, DeserializationContext ctxt) thr
}

/**
* @since 2.18
* @since 2.19
*/
public Map<Object, Object> initMap(DeserializationContext context, SettableAnyProperty anySetter)
throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static SettableAnyProperty constructForJsonNodeField(DeserializationConte
}

/**
* @since 2.18
* @since 2.19
*/
public static SettableAnyProperty constructForMapParameter(DeserializationContext ctxt,
BeanProperty property,
Expand Down Expand Up @@ -462,7 +462,7 @@ public SettableAnyProperty withValueDeserializer(JsonDeserializer<Object> deser)
}

/**
* @since 2.18
* @since 2.19
*/
protected static class MapParameterAnyProperty extends SettableAnyProperty
implements java.io.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@ public Object createFromObjectWith(DeserializationContext ctxt,
return createFromObjectWith(ctxt, buffer.getParameters(props));
}

public Object createFromObjectWith(DeserializationContext ctxt,
SettableBeanProperty[] props, PropertyValueBuffer buffer, SettableAnyProperty anySetter)
throws IOException
{
return createFromObjectWith(ctxt, buffer.getParametersWithAnySetter(props, anySetter));
}

/**
* Method to called to create value instance from JSON Object using
* an intermediate "delegate" value to pass to createor method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.core.JsonParser;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.CreatorProperty;
import com.fasterxml.jackson.databind.deser.SettableAnyProperty;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
Expand Down Expand Up @@ -188,6 +189,16 @@ public SettableBeanProperty findCreatorProperty(int propertyIndex) {
/**********************************************************
*/

/**
* Method called when starting to build a bean instance.
*
* @since 2.19 (added SettableAnyProperty parameter)
*/
public PropertyValueBuffer startBuildingWithAnySetter(JsonParser p, DeserializationContext ctxt,
ObjectIdReader oir, SettableAnyProperty anySetter) {
return new PropertyValueBuffer(p, ctxt, _propertyCount, oir, anySetter);
}

/**
* Method called when starting to build a bean instance.
*
Expand All @@ -198,12 +209,6 @@ public PropertyValueBuffer startBuilding(JsonParser p, DeserializationContext ct
return new PropertyValueBuffer(p, ctxt, _propertyCount, oir);
}

public Object buildWithAnySetter(DeserializationContext ctxt, PropertyValueBuffer buffer, SettableAnyProperty anySetter) throws IOException
{
return _valueInstantiator.createFromObjectWith(ctxt,
_allProperties, buffer, anySetter);
}

public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) throws IOException
{
Object bean = _valueInstantiator.createFromObjectWith(ctxt,
Expand All @@ -221,6 +226,20 @@ public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) thr
return bean;
}

public CreatorProperty findAnySetterProp() {
for (SettableBeanProperty prop : _allProperties) {
if (!(prop instanceof CreatorProperty)) {
continue;
}
CreatorProperty cp = (CreatorProperty) prop;
if (!cp.isAnySetterProp()) {
continue;
}
return cp;
}
return null;
}

/*
/**********************************************************
/* Helper classes
Expand Down

0 comments on commit 8612433

Please sign in to comment.