-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add any-setter handling in PropertyValueBuffer
post #562
#4720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f8a9932
215d019
c4e870c
3a13eac
e842699
6cc443c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,11 @@ | |
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.deser.SettableAnyProperty; | ||
import com.fasterxml.jackson.databind.deser.SettableBeanProperty; | ||
import com.fasterxml.jackson.databind.exc.ValueInstantiationException; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMember; | ||
|
||
/** | ||
|
@@ -135,6 +137,12 @@ public PropertyValueBuffer(JsonParser p, DeserializationContext ctxt, int paramC | |
*/ | ||
public final boolean hasParameter(SettableBeanProperty prop) | ||
{ | ||
// 28-Sep-2024 : [databind#4508] Support any-setter flowing through creator | ||
if (_anyParamSetter != null) { | ||
if (prop.getCreatorIndex() == _anyParamSetter.getParameterIndex()) { | ||
return true; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if this is the most optimal way of checking, any idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me rewrite it slightly, considering that expectation is that match (true) is more likely than non-match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrite looks cleaner, thanks! |
||
if (_paramsSeenBig == null) { | ||
return ((_paramsSeen >> prop.getCreatorIndex()) & 1) == 1; | ||
} | ||
|
@@ -160,6 +168,16 @@ public Object getParameter(SettableBeanProperty prop) | |
} else { | ||
value = _creatorParameters[prop.getCreatorIndex()] = _findMissing(prop); | ||
} | ||
// 28-Sep-2024 : [databind#4508] Support any-setter flowing through creator | ||
if ((value == null) && (_anyParamSetter != null ) | ||
&& (prop.getCreatorIndex() == _anyParamSetter.getParameterIndex())) { | ||
try { | ||
value = _createAndSetAnySetterValue(); | ||
} catch (IOException e) { | ||
// do-nothing here? | ||
throw JsonMappingException.fromUnexpectedIOE(e); | ||
} | ||
} | ||
if (value == null && _context.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) { | ||
return _context.reportInputMismatch(prop, | ||
"Null value for creator property '%s' (index %d); `DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES` enabled", | ||
|
@@ -198,11 +216,7 @@ public Object[] getParameters(SettableBeanProperty[] props) | |
} | ||
// [databind#562] since 2.18 : Respect @JsonAnySetter in @JsonCreator | ||
if (_anyParamSetter != null) { | ||
Object anySetterParameterObject = _anyParamSetter.createParameterObject(); | ||
for (PropertyValue pv = _anyParamBuffered; pv != null; pv = pv.next) { | ||
pv.setValue(anySetterParameterObject); | ||
} | ||
_creatorParameters[_anyParamSetter.getParameterIndex()] = anySetterParameterObject; | ||
_creatorParameters[_anyParamSetter.getParameterIndex()] = _createAndSetAnySetterValue(); | ||
} | ||
if (_context.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) { | ||
for (int ix = 0; ix < props.length; ++ix) { | ||
|
@@ -217,6 +231,20 @@ public Object[] getParameters(SettableBeanProperty[] props) | |
return _creatorParameters; | ||
} | ||
|
||
/** | ||
* Helper method called to create and set any values buffered for "any setter" | ||
* | ||
* @since 2.18 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need since annotations on private methods? In which case, this is wrong, it should be 2.18.1 - be I prefer not to annotate private methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. |
||
*/ | ||
private Object _createAndSetAnySetterValue() throws IOException | ||
{ | ||
Object anySetterParameterObject = _anyParamSetter.createParameterObject(); | ||
for (PropertyValue pv = _anyParamBuffered; pv != null; pv = pv.next) { | ||
pv.setValue(anySetterParameterObject); | ||
} | ||
return anySetterParameterObject; | ||
} | ||
|
||
protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingException | ||
{ | ||
// 08-Jun-2024: [databind#562] AnySetters are bit special | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.18.0 is released already - shouldn't this be in the 2.18.1 section?