Skip to content

Commit efa6044

Browse files
committed
Fixed #2280
1 parent 441b65c commit efa6044

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

release-notes/CREDITS-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ Joe Schafer (jschaf@github)
756756
Deblock Thomas (deblockt@github)
757757
* Reported, contributed fix for #1912: `BeanDeserializerModifier.updateBuilder()` does not
758758
work to set custom deserializer on a property (since 2.9.0)
759-
(contributed by Deblock T)
759+
(2.9.5)
760+
* Reported, suggested fix for #2280: JsonMerge not work with constructor args
761+
(2.10.0)
760762
761763
762764
* Reported #1931: Two more `c3p0` gadgets to exploit default typing issue

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Project: jackson-databind
4242
#2251: Getter that returns an abstract collection breaks a delegating `@JsonCreator`
4343
#2265: Inconsistent handling of Collections$UnmodifiableList vs Collections$UnmodifiableRandomAccessListq
4444
#2273: Add basic Java 9+ module info
45+
#2280: JsonMerge not work with constructor args
46+
(reported by Deblock T)
4547
#2311: Unnecessary MultiView creation for property writers
4648
(suggested by Manuel H)
4749
#2338: Suboptimal return type for `JsonNode.withArray()`

src/main/java/com/fasterxml/jackson/databind/deser/CreatorProperty.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,20 @@ public Object setAndReturn(Object instance, Object value) throws IOException
253253
_verifySetter();
254254
return _fallbackSetter.setAndReturn(instance, value);
255255
}
256-
256+
257+
@Override
258+
public PropertyMetadata getMetadata() {
259+
// 03-Jun-2019, tatu: Added as per [databind#2280] to support merge.
260+
// Not 100% sure why it would be needed (or fixes things) but... appears to.
261+
// Need to understand better in future as it seems like it should probably be
262+
// linked earlier during construction or something.
263+
PropertyMetadata md = super.getMetadata();
264+
if (_fallbackSetter != null) {
265+
return md.withMergeInfo(_fallbackSetter.getMetadata().getMergeInfo());
266+
}
267+
return md;
268+
}
269+
257270
@Override
258271
public Object getInjectableValueId() {
259272
return _injectableValueId;

src/test/java/com/fasterxml/jackson/databind/deser/merge/PropertyMergeTest.java

+38
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ static class CantMergeInts {
8787
public int value;
8888
}
8989

90+
// [databind#2280]
91+
static class ConstructorArgsPojo {
92+
static class MergeablePojo {
93+
public String foo;
94+
public String bar;
95+
96+
public MergeablePojo(String foo, String bar) {
97+
this.foo = foo;
98+
this.bar = bar;
99+
}
100+
}
101+
102+
public MergeablePojo mergeableBean;
103+
104+
@JsonCreator
105+
public ConstructorArgsPojo(@JsonMerge @JsonProperty("mergeableBean") MergeablePojo mergeableBean) {
106+
this.mergeableBean = mergeableBean;
107+
}
108+
}
109+
90110
/*
91111
/********************************************************
92112
/* Test methods, POJO merging
@@ -153,6 +173,24 @@ public void testBeanMergingWithoutSetter() throws Exception
153173
assertEquals(1, config._value.a);
154174
}
155175

176+
/*
177+
/********************************************************
178+
/* Test methods, Creators
179+
/********************************************************
180+
*/
181+
182+
// [databind#2280]
183+
public void testBeanMergeUsingConstructors() throws Exception {
184+
ConstructorArgsPojo input = new ConstructorArgsPojo(new ConstructorArgsPojo.MergeablePojo("foo", "bar"));
185+
186+
ConstructorArgsPojo result = MAPPER.setDefaultMergeable(true)
187+
.readerForUpdating(input)
188+
.readValue(aposToQuotes("{'mergeableBean': {'foo': 'newFoo'}}"));
189+
190+
assertEquals("newFoo", result.mergeableBean.foo);
191+
assertEquals("bar", result.mergeableBean.bar);
192+
}
193+
156194
/*
157195
/********************************************************
158196
/* Test methods, as array

0 commit comments

Comments
 (0)