Fixed [JACKSON-831], probs with external type id, property
diff --git a/release-notes/CREDITS b/release-notes/CREDITS
index 4cc71eb..43f3e57 100644
--- a/release-notes/CREDITS
+++ b/release-notes/CREDITS
@@ -900,14 +900,18 @@
properties, @JsonSerialize(contentUsing)
[1.9.7]
+Laurent Pireyn:
+ * Reported [JACKSON-831] External type id, explicit property do not work well together
+ [1.9.7]
+
Jan Jan:
* Reported [JACKSON-832] (partial) Fix numeric range check for Longs (was not working)
[1.9.7]
-Stuart Dootson:
- * Reported [Issue-13] Runtime error passing multiple injected values to a constructor
+Klaus Reimer:
+ * [JACKSON-834] Could not use @JsonFactory with non-String argument with Enums
[1.9.7]
-Klaus Reimer:
- * [JACKSON-834] Could not use @JsonFactory with non-String argument with Enums
+Stuart Dootson:
+ * Reported [Issue-13] Runtime error passing multiple injected values to a constructor
[1.9.7]
diff --git a/release-notes/VERSION b/release-notes/VERSION
index 70f8fbb..39deab3 100644
--- a/release-notes/VERSION
+++ b/release-notes/VERSION
@@ -24,6 +24,8 @@
* [JACKSON-829] Custom serializers not working for List<String> properties,
@JsonSerialize(contentUsing)
(reported by James R)
+ * [JACKSON-831] External type id, explicit property do not work well together
+ (reported by Laurent P)
* [JACKSON-832] (partial) Fix numeric range check for Longs (was not working)
(reported by Jan J)
* [JACKSON-834] Could not use @JsonFactory with non-String argument with Enums
diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java
index bcd197a..3e9630a 100644
--- a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java
+++ b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializer.java
@@ -1213,6 +1213,10 @@
jp.nextToken();
SettableBeanProperty prop = _beanProperties.find(propName);
if (prop != null) { // normal case
+ // [JACKSON-831]: may have property AND be used as external type id:
+ if (jp.getCurrentToken().isScalarValue()) {
+ ext.handleTypePropertyValue(jp, ctxt, propName, bean);
+ }
try {
prop.deserializeAndSet(jp, ctxt, bean);
} catch (Exception e) {
diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/impl/ExternalTypeHandler.java b/src/mapper/java/org/codehaus/jackson/map/deser/impl/ExternalTypeHandler.java
index 38b7df1..335ff2c 100644
--- a/src/mapper/java/org/codehaus/jackson/map/deser/impl/ExternalTypeHandler.java
+++ b/src/mapper/java/org/codehaus/jackson/map/deser/impl/ExternalTypeHandler.java
@@ -50,6 +50,38 @@
}
/**
+ * Method called to see if given property/value pair is an external type
+ * id; and if so handle it. This is <b>only</b> to be called in case
+ * containing POJO has similarly named property as the external type id;
+ * otherwise {@link #handleToken} should be called instead.
+ */
+ public boolean handleTypePropertyValue(JsonParser jp, DeserializationContext ctxt,
+ String propName, Object bean)
+ throws IOException, JsonProcessingException
+ {
+ Integer I = _nameToPropertyIndex.get(propName);
+ if (I == null) {
+ return false;
+ }
+ int index = I.intValue();
+ ExtTypedProperty prop = _properties[index];
+ if (!prop.hasTypePropertyName(propName)) {
+ return false;
+ }
+ _typeIds[index] = jp.getText();
+ // note: can NOT skip child values (should always be String anyway)
+ boolean canDeserialize = (bean != null) && (_tokens[index] != null);
+ // Minor optimization: deserialize properties as soon as we have all we need:
+ if (canDeserialize) {
+ _deserialize(jp, ctxt, bean, index);
+ // clear stored data, to avoid deserializing+setting twice:
+ _typeIds[index] = null;
+ _tokens[index] = null;
+ }
+ return true;
+ }
+
+ /**
* Method called to ask handler to handle
*/
public boolean handleToken(JsonParser jp, DeserializationContext ctxt,
diff --git a/src/test/org/codehaus/jackson/map/jsontype/TestExternalId.java b/src/test/org/codehaus/jackson/map/jsontype/TestExternalId.java
index efbefa7..44c3698 100644
--- a/src/test/org/codehaus/jackson/map/jsontype/TestExternalId.java
+++ b/src/test/org/codehaus/jackson/map/jsontype/TestExternalId.java
@@ -204,5 +204,6 @@
assertNotNull(result);
assertNotNull(result.pet);
assertSame(Dog.class, result.pet.getClass());
+ assertEquals("dog", result.petType);
}
}