Fix #1437
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/impl/MergingSettableBeanProperty.java b/src/main/java/com/fasterxml/jackson/databind/deser/impl/MergingSettableBeanProperty.java
index 133f671..22c4c4e 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/impl/MergingSettableBeanProperty.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/impl/MergingSettableBeanProperty.java
@@ -10,8 +10,12 @@
/**
* {@link SettableBeanProperty} implementation that will try to access value of
* the property first, and if non-null value found, pass that for update
- * (using {@link com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext, Object)}
- * ) instead of constructing a new value. This is necessary to support "merging" properties.
+ * (using {@link com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext, Object)})
+ * instead of constructing a new value. This is necessary to support "merging" properties.
+ *<p>
+ * Note that there are many similarities to {@link SetterlessProperty}, which predates
+ * this variant; and that one is even used in cases where there is no mutator
+ * available.
*
* @since 2.9
*/
@@ -76,7 +80,11 @@
newValue = delegate.deserializeWith(p, ctxt, oldValue);
}
if (newValue != oldValue) {
- delegate.set(instance, newValue);
+ // 31-Oct-2016, tatu: Basically should just ignore as null can't really
+ // contribute to merging.
+ if (newValue != null) {
+ delegate.set(instance, newValue);
+ }
}
}
@@ -97,20 +105,31 @@
// try calling setter on builder? Presumably should not be required,
// but may need to revise
if (newValue != oldValue) {
- return delegate.setAndReturn(instance, newValue);
+ // 31-Oct-2016, tatu: Basically should just ignore as null can't really
+ // contribute to merging.
+ if (newValue != null) {
+ return delegate.setAndReturn(instance, newValue);
+ }
}
return instance;
}
@Override
public void set(Object instance, Object value) throws IOException {
- delegate.set(instance, value);
+ // 31-Oct-2016, tatu: Basically should just ignore as null can't really
+ // contribute to merging.
+ if (value != null) {
+ delegate.set(instance, value);
+ }
}
@Override
- public Object setAndReturn(Object instance, Object value)
- throws IOException
- {
- return delegate.setAndReturn(instance, value);
+ public Object setAndReturn(Object instance, Object value) throws IOException {
+ // 31-Oct-2016, tatu: Basically should just ignore as null can't really
+ // contribute to merging.
+ if (value != null) {
+ return delegate.setAndReturn(instance, value);
+ }
+ return instance;
}
}
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/impl/SetterlessProperty.java b/src/main/java/com/fasterxml/jackson/databind/deser/impl/SetterlessProperty.java
index fc35abd..f2fbb55 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/impl/SetterlessProperty.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/impl/SetterlessProperty.java
@@ -145,6 +145,6 @@
public Object setAndReturn(Object instance, Object value) throws IOException
{
set(instance, value);
- return null;
+ return instance;
}
}
\ No newline at end of file
diff --git a/src/test/java/com/fasterxml/jackson/failing/MergeWithNullTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/merge/MergeWithNullTest.java
similarity index 65%
rename from src/test/java/com/fasterxml/jackson/failing/MergeWithNullTest.java
rename to src/test/java/com/fasterxml/jackson/databind/deser/merge/MergeWithNullTest.java
index 2637c55..b7a09fe 100644
--- a/src/test/java/com/fasterxml/jackson/failing/MergeWithNullTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/deser/merge/MergeWithNullTest.java
@@ -1,4 +1,4 @@
-package com.fasterxml.jackson.failing;
+package com.fasterxml.jackson.databind.deser.merge;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.OptBoolean;
@@ -19,6 +19,14 @@
}
}
+ // another variant where all we got is a getter
+ static class NoSetterConfig {
+ AB _value = new AB(2, 3);
+
+ @JsonSetter(merge=OptBoolean.TRUE)
+ public AB getValue() { return _value; }
+ }
+
static class AB {
public int a;
public int b;
@@ -29,7 +37,7 @@
b = b0;
}
}
-
+
private final ObjectMapper MAPPER = new ObjectMapper()
// 26-Oct-2016, tatu: Make sure we'll report merge problems by default
.disable(MapperFeature.IGNORE_MERGE_FOR_UNMERGEABLE)
@@ -44,6 +52,15 @@
assertEquals(5, config.loc.a);
assertEquals(7, config.loc.b);
}
-
+ public void testSetterlessMergingWithNull() throws Exception
+ {
+ NoSetterConfig input = new NoSetterConfig();
+ NoSetterConfig result = MAPPER.readerForUpdating(input)
+ .readValue(aposToQuotes("{'value':null}"));
+ assertNotNull(result.getValue());
+ assertEquals(2, result.getValue().a);
+ assertEquals(3, result.getValue().b);
+ assertSame(input, result);
+ }
}