Fixed [JACKSON-774]
diff --git a/release-notes/CREDITS b/release-notes/CREDITS
index 6948c19..2abe00a 100644
--- a/release-notes/CREDITS
+++ b/release-notes/CREDITS
@@ -855,6 +855,11 @@
of EnumMap, regular Map, or contents of EnumSet
[1.9.4]
+Nathaniel Bauernfeind:
+ * Reported [JACKSON-774]: PropertyBasedCreator not using JsonDeserializer.getNullValue()
+ [1.9.5]
+
Ittai Zeidman:
* Reported [JACKSON-775]: MissingNode.asText() should return "", not null
[1.9.5]
+
\ No newline at end of file
diff --git a/release-notes/VERSION b/release-notes/VERSION
index b5eb9c8..7720980 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -11,6 +11,8 @@
* [JACKSON-757]: further fixing (1.9.4 had partial fix)
* [JACKSON-773]: Bug in SimpleFilterProvider constructor
(reported by Kenny M)
+ * [JACKSON-774]: PropertyBasedCreator was not using JsonDeserializer.getNullValue()
+ (reported by Nathaniel B)
* [JACKSON-775]: MissingNode.asText() should return "", not null
(reported by Ittai Z)
diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/impl/PropertyBasedCreator.java b/src/mapper/java/org/codehaus/jackson/map/deser/impl/PropertyBasedCreator.java
index 8da1777..fbf59cb 100644
--- a/src/mapper/java/org/codehaus/jackson/map/deser/impl/PropertyBasedCreator.java
+++ b/src/mapper/java/org/codehaus/jackson/map/deser/impl/PropertyBasedCreator.java
@@ -34,7 +34,7 @@
* If some property values must always have a non-null value (like
* primitive types do), this array contains such default values.
*/
- protected final Object[] _defaultValues;
+ protected Object[] _defaultValues;
/**
* Array that contains properties that expect value to inject, if any;
@@ -84,6 +84,13 @@
public void assignDeserializer(SettableBeanProperty prop, JsonDeserializer<Object> deser) {
prop = prop.withValueDeserializer(deser);
_properties.put(prop.getName(), prop);
+ Object nullValue = deser.getNullValue();
+ if (nullValue != null) {
+ if (_defaultValues == null) {
+ _defaultValues = new Object[_properties.size()];
+ }
+ _defaultValues[prop.getPropertyIndex()] = nullValue;
+ }
}
/**
diff --git a/src/test/org/codehaus/jackson/map/deser/TestCreatorNullValue.java b/src/test/org/codehaus/jackson/map/deser/TestCreatorNullValue.java
new file mode 100644
index 0000000..8239e41
--- /dev/null
+++ b/src/test/org/codehaus/jackson/map/deser/TestCreatorNullValue.java
@@ -0,0 +1,82 @@
+package org.codehaus.jackson.map.deser;
+
+import org.codehaus.jackson.*;
+import org.codehaus.jackson.annotate.*;
+import org.codehaus.jackson.map.*;
+import org.codehaus.jackson.type.JavaType;
+
+// for [JACKSON-774]
+@SuppressWarnings("rawtypes")
+public class TestCreatorNullValue extends BaseMapTest
+{
+ private static class Container {
+ Contained<String> contained;
+
+ @SuppressWarnings("unused")
+ @JsonCreator
+ public Container(@JsonProperty("contained") Contained<String> contained) {
+ this.contained = contained;
+ }
+ }
+
+ private static interface Contained<T> {}
+
+ private static class NullContained implements Contained<Object> {}
+
+ private static final NullContained NULL_CONTAINED = new NullContained();
+
+ private static class ContainedDeserializer extends JsonDeserializer<Contained> {
+ @Override
+ public Contained deserialize(JsonParser jp, DeserializationContext ctxt) throws JsonProcessingException {
+ return null;
+ }
+
+ @Override
+ public Contained getNullValue() {
+ return NULL_CONTAINED;
+ }
+ }
+
+ private static class ContainerDeserializerResolver extends Deserializers.Base {
+ @Override
+ public JsonDeserializer<?> findBeanDeserializer(JavaType type,
+ DeserializationConfig config, DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property)
+ throws JsonMappingException {
+ if (!Contained.class.isAssignableFrom(type.getRawClass())) {
+ return null;
+ } else {
+ return new ContainedDeserializer();
+ }
+ }
+ }
+
+ private static class TestModule extends Module {
+ @Override
+ public String getModuleName() {
+ return "ContainedModule";
+ }
+
+ @Override
+ public Version version() {
+ return Version.unknownVersion();
+ }
+
+ @Override
+ public void setupModule(SetupContext setupContext) {
+ setupContext.addDeserializers(new ContainerDeserializerResolver());
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Unit tests
+ /**********************************************************
+ */
+
+ public void testUsesDeserializersNullValue() throws Exception {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.registerModule(new TestModule());
+ Container container = mapper.readValue("{}", Container.class);
+ assertEquals(NULL_CONTAINED, container.contained);
+ }
+}
\ No newline at end of file