Skip to content

Commit

Permalink
Merge branch '2.18' into 2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 29, 2024
2 parents babed2d + a79ce09 commit dcb98cb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1834,3 +1834,6 @@ Rikkarth (rikkarth@github)
* Contributed #4709: Add `JacksonCollectors` with `toArrayNode()` implementation
(2.18.0)

Maxim Valeev (@MaximValeev)
* Reported #4508: Deserialized JsonAnySetter field in Kotlin data class is null
(2.18.1)
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Project: jackson-databind

-

2.18.1 (WIP-2024)

#4508: Deserialized JsonAnySetter field in Kotlin data class is null
(reported by @MaximValeev)
(fix by Joo-Hyuk K)

2.18.0 (26-Sep-2024)

#562: Allow `@JsonAnySetter` to flow through Creators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,24 @@ public PropertyValueBuffer(JsonParser p, DeserializationContext ctxt, int paramC
*/
public final boolean hasParameter(SettableBeanProperty prop)
{
final int ix = prop.getCreatorIndex();

if (_paramsSeenBig == null) {
return ((_paramsSeen >> prop.getCreatorIndex()) & 1) == 1;
if (((_paramsSeen >> ix) & 1) == 1) {
return true;
}
} else {
if (_paramsSeenBig.get(ix)) {
return true;
}
}
return _paramsSeenBig.get(prop.getCreatorIndex());
// 28-Sep-2024 : [databind#4508] Support any-setter flowing through creator
if (_anyParamSetter != null) {
if (ix == _anyParamSetter.getParameterIndex()) {
return true;
}
}
return false;
}

/**
Expand All @@ -160,6 +174,11 @@ 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())) {
value = _createAndSetAnySetterValue();
}
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",
Expand Down Expand Up @@ -198,11 +217,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) {
Expand All @@ -217,6 +232,27 @@ public Object[] getParameters(SettableBeanProperty[] props)
return _creatorParameters;
}

/**
* Helper method called to create and set any values buffered for "any setter"
*/
private Object _createAndSetAnySetterValue() throws JsonMappingException
{
Object anySetterParameterObject = _anyParamSetter.createParameterObject();
for (PropertyValue pv = _anyParamBuffered; pv != null; pv = pv.next) {
try {
pv.setValue(anySetterParameterObject);

// Since one of callers only exposes JsonMappingException, but pv.setValue()
// nominally leaks IOException, need to do this unfortunate conversion
} catch (JsonMappingException e) {
throw e;
} catch (IOException e) {
throw JsonMappingException.fromUnexpectedIOE(e);
}
}
return anySetterParameterObject;
}

protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingException
{
// 08-Jun-2024: [databind#562] AnySetters are bit special
Expand Down

0 comments on commit dcb98cb

Please sign in to comment.