Skip to content

Commit

Permalink
Fix #4356: BeanDeserializerModifier.updateBuilder() not working for C…
Browse files Browse the repository at this point in the history
…reator props
  • Loading branch information
cowtowncoder committed Jun 1, 2024
1 parent 5c9b032 commit be53d94
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,11 @@ Ulf Dreyer (u3r@github)
* Reported #4085: `@JsonView` does not work on class-level for records
(2.18.0)

Mark Herkrath (herkrath@github)
* Reported #4356: `BeanDeserializerModifier::updateBuilder()` doesn't work for
beans with Creator methods
(2.18.0)
David Moten (davidmoten@github)
* Contributed #4453: Allow JSON Integer to deserialize into a single-arg constructor of
parameter type `double`
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Project: jackson-databind
#4119: Exception when deserialization uses a record with a constructor
property with `access=READ_ONLY`
(reported by @Mochis)
#4356: `BeanDeserializerModifier::updateBuilder()` doesn't work for
beans with Creator methods
(reported by Mark H)
#4452: `@JsonProperty` not serializing field names properly
on `@JsonCreator` in Record
(reported by @Incara)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public class BeanDeserializerBuilder
final protected Map<String, SettableBeanProperty> _properties
= new LinkedHashMap<String, SettableBeanProperty>();

/**
* Parameters of the primary properties-based Creator, if any.
*
* @since 2.18
*/
protected SettableBeanProperty[] _propsBasedCreatorParams;

/**
* Value injectors for deserialization
*/
Expand Down Expand Up @@ -146,6 +153,7 @@ protected BeanDeserializerBuilder(BeanDeserializerBuilder src)
_ignorableProps = src._ignorableProps;
_includableProps = src._includableProps;
_valueInstantiator = src._valueInstantiator;
_propsBasedCreatorParams = src._propsBasedCreatorParams;
_objectIdReader = src._objectIdReader;

_anySetter = src._anySetter;
Expand Down Expand Up @@ -174,7 +182,14 @@ private static <T> List<T> _copy(List<T> src) {
* Method for adding a new property or replacing a property.
*/
public void addOrReplaceProperty(SettableBeanProperty prop, boolean allowOverride) {
_properties.put(prop.getName(), prop);
SettableBeanProperty oldProp = _properties.put(prop.getName(), prop);
if ((oldProp != null) && (_propsBasedCreatorParams != null)) {
for (int i = 0, len = _propsBasedCreatorParams.length; i < len; ++i) {
if (_propsBasedCreatorParams[i] == oldProp) {
_propsBasedCreatorParams[i] = prop;
}
}
}
}

/**
Expand Down Expand Up @@ -295,6 +310,7 @@ public void setIgnoreUnknownProperties(boolean ignore) {

public void setValueInstantiator(ValueInstantiator inst) {
_valueInstantiator = inst;
_propsBasedCreatorParams = inst.getFromObjectArguments(_config);
}

public void setObjectIdReader(ObjectIdReader r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
}
}

private final ObjectMapper MAPPER = jsonMapperBuilder().addModule(getSimpleModuleWithDeserializerModifier()).build();
private final ObjectMapper MAPPER = jsonMapperBuilder()
.addModule(getSimpleModuleWithDeserializerModifier())
.build();

// passes
@Test
Expand Down

0 comments on commit be53d94

Please sign in to comment.